From cec6bd5eb5e1798392a41b7c8c8cca478722f3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 27 May 2019 13:21:35 +0200 Subject: [PATCH 01/98] fill select boxes with default values to avoid empty list Since this list view is the only one in which an empty table is displayed before the user specifies what he wants to see via the select boxes, a preselection is defined by "default-values". The default language is set with the default site language, because normally the translations start from this language. --- .../Model/AssociationsModel.php | 23 ++++++++++++++----- .../View/Associations/HtmlView.php | 11 +++++++++ .../forms/filter_associations.xml | 4 +--- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index da696f3ebff5d..4da7ea72302c8 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -11,6 +11,7 @@ defined('_JEXEC') or die; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; @@ -79,6 +80,10 @@ protected function populateState($ordering = 'ordering', $direction = 'asc') $forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd'); $forcedItemType = $app->input->get('forcedItemType', '', 'string'); + // Set default itemtype and default language to default site language + $defaultLanguage = ComponentHelper::getParams('com_languages')->get('site'); + $defaultItemType = 'com_content.article'; + // Adjust the context to support modal layouts. if ($layout = $app->input->get('layout')) { @@ -97,12 +102,14 @@ protected function populateState($ordering = 'ordering', $direction = 'asc') $this->context .= '.' . $forcedItemType; } - $this->setState('itemtype', $this->getUserStateFromRequest($this->context . '.itemtype', 'itemtype', '', 'string')); - $this->setState('language', $this->getUserStateFromRequest($this->context . '.language', 'language', '', 'string')); + $this->setState('itemtype', $this->getUserStateFromRequest($this->context . '.itemtype', 'itemtype', $defaultItemType, 'string')); + $this->setState('language', $this->getUserStateFromRequest($this->context . '.language', 'language', $defaultLanguage, 'string')); $this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string')); $this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'cmd')); - $this->setState('filter.category_id', $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '', 'cmd')); + $this->setState('filter.category_id', + $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '', 'cmd') + ); $this->setState('filter.menutype', $this->getUserStateFromRequest($this->context . '.filter.menutype', 'filter_menutype', '', 'string')); $this->setState('filter.access', $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', '', 'string')); $this->setState('filter.level', $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level', '', 'cmd')); @@ -231,14 +238,16 @@ protected function getListQuery() $query->select($db->quoteName($fields['language'], 'language')) ->select($db->quoteName('l.title', 'language_title')) ->select($db->quoteName('l.image', 'language_image')) - ->join('LEFT', $db->quoteName('#__languages', 'l') . ' ON ' . $db->quoteName('l.lang_code') . ' = ' . $db->quoteName($fields['language'])); + ->join('LEFT', $db->quoteName('#__languages', 'l') + . ' ON ' . $db->quoteName('l.lang_code') . ' = ' . $db->quoteName($fields['language']) + ); // Join over the associations. $query->select('COUNT(' . $db->quoteName('asso2.id') . ') > 1 AS ' . $db->quoteName('association')) ->join( 'LEFT', $db->quoteName('#__associations', 'asso') . ' ON ' . $db->quoteName('asso.id') . ' = ' . $db->quoteName($fields['id']) - . ' AND ' . $db->quoteName('asso.context') . ' = ' . $db->quote($extensionName . '.' . 'item') + . ' AND ' . $db->quoteName('asso.context') . ' = ' . $db->quote($extensionName . '.item') ) ->join('LEFT', $db->quoteName('#__associations', 'asso2') . ' ON ' . $db->quoteName('asso2.key') . ' = ' . $db->quoteName('asso.key')); @@ -320,7 +329,9 @@ protected function getListQuery() // Join over the menu types. $query->select($db->quoteName('mt.title', 'menutype_title')) ->select($db->quoteName('mt.id', 'menutypeid')) - ->join('LEFT', $db->quoteName('#__menu_types', 'mt') . ' ON ' . $db->quoteName('mt.menutype') . ' = ' . $db->quoteName($fields['menutype'])); + ->join('LEFT', $db->quoteName('#__menu_types', 'mt') + . ' ON ' . $db->quoteName('mt.menutype') . ' = ' . $db->quoteName($fields['menutype']) + ); $groupby[] = 'mt.title'; $groupby[] = 'mt.id'; diff --git a/administrator/components/com_associations/View/Associations/HtmlView.php b/administrator/components/com_associations/View/Associations/HtmlView.php index b57b4b8312cd9..a2b9ba4e36eee 100644 --- a/administrator/components/com_associations/View/Associations/HtmlView.php +++ b/administrator/components/com_associations/View/Associations/HtmlView.php @@ -77,6 +77,17 @@ public function display($tpl = null) $this->filterForm = $this->get('FilterForm'); $this->activeFilters = $this->get('ActiveFilters'); + // Get default values and set these to selected to the select boxes + if ($this->state->get('itemtype')) + { + $this->filterForm->setValue('itemtype', null, $this->state->get('itemtype')); + } + + if ($this->state->get('language')) + { + $this->filterForm->setValue('language', null, $this->state->get('language')); + } + if (!Associations::isEnabled()) { $link = Route::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . AssociationsHelper::getLanguagefilterPluginId()); diff --git a/administrator/components/com_associations/forms/filter_associations.xml b/administrator/components/com_associations/forms/filter_associations.xml index a73cc743c0aa1..d865248ba313d 100644 --- a/administrator/components/com_associations/forms/filter_associations.xml +++ b/administrator/components/com_associations/forms/filter_associations.xml @@ -4,9 +4,8 @@ name="itemtype" type="itemtype" filtermode="selector" - onchange="Joomla.resetFilters(this)" + onchange="this.form.submit()" > - - From 57c3a12f38470bf73a1e1729953f0e5a3a8682ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 27 May 2019 17:08:53 +0200 Subject: [PATCH 02/98] Display always the toolbar and adjust its functions Since the selectboxes now always have a value, the buttons Delete associations and delete orphans of the toolbar are now always displayed. The "delete associations"-button now only deletes associations in which the user is currently located. - In addition, the button was adapted to a Confirm button, so that the associated js file and the associated message text could be removed. - The context is now also included as info in the message text. --- .../Controller/AssociationsController.php | 5 +++-- .../Model/AssociationsModel.php | 21 ++++++++++++++++++- .../View/Associations/HtmlView.php | 13 ++++++------ .../tmpl/associations/default.php | 4 +--- .../language/en-GB/en-GB.com_associations.ini | 2 +- .../js/admin-associations-default.es6.js | 18 ---------------- 6 files changed, 32 insertions(+), 31 deletions(-) delete mode 100644 build/media_source/com_associations/js/admin-associations-default.es6.js diff --git a/administrator/components/com_associations/Controller/AssociationsController.php b/administrator/components/com_associations/Controller/AssociationsController.php index f5c362d5a3f01..f4e98420b8abd 100644 --- a/administrator/components/com_associations/Controller/AssociationsController.php +++ b/administrator/components/com_associations/Controller/AssociationsController.php @@ -49,7 +49,7 @@ public function getModel($name = 'Associations', $prefix = 'Administrator', $con } /** - * Method to purge the associations table. + * Method to purge the associations table by context. * * @return void * @@ -57,7 +57,8 @@ public function getModel($name = 'Associations', $prefix = 'Administrator', $con */ public function purge() { - $this->getModel('associations')->purge(); + $context = $this->input->getString('itemtype'); + $this->getModel('associations')->purge($context); $this->setRedirect(Route::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); } diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 4da7ea72302c8..631cca3ee71cf 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -474,7 +474,26 @@ public function purge($context = '', $key = '') // Filter by associations context. if ($context) { - $query->where($db->quoteName('context') . ' = ' . $db->quote($context)); + list($extensionName, $typeName) = explode('.', $context, 2); + + // The associations of the type category may only be deleted with the appropriate context, + // therefore with the appropriate extension. Not all categories. + if ($typeName === 'category') + { + // Subquery: Search for category-items with the given context + $subQuery = $db->getQuery(true) + ->select($db->quoteName('id')) + ->from($db->quoteName('#__categories')) + ->where($db->quoteName('extension') . ' = ' . $db->quote($extensionName)); + + // Delete associations of categories with the given context by comparing id of both tables + $query->where($db->quoteName('id') . ' IN (' . $subQuery . ')') + ->where($db->quoteName('context') . ' = ' . $db->quote('com_categories.item')); + } + else + { + $query->where($db->quoteName('context') . ' = ' . $db->quote($extensionName . '.item')); + } } // Filter by key. diff --git a/administrator/components/com_associations/View/Associations/HtmlView.php b/administrator/components/com_associations/View/Associations/HtmlView.php index a2b9ba4e36eee..9ed6a6a459fb4 100644 --- a/administrator/components/com_associations/View/Associations/HtmlView.php +++ b/administrator/components/com_associations/View/Associations/HtmlView.php @@ -16,6 +16,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\Router\Route; +use Joomla\CMS\Toolbar\Toolbar; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper; @@ -225,6 +226,7 @@ public function display($tpl = null) protected function addToolbar() { $user = Factory::getUser(); + $toolbar = Toolbar::getInstance('toolbar'); if (isset($this->typeName) && isset($this->extensionName)) { @@ -251,12 +253,11 @@ protected function addToolbar() if ($user->authorise('core.admin', 'com_associations') || $user->authorise('core.options', 'com_associations')) { - if (!isset($this->typeName)) - { - ToolbarHelper::custom('associations.purge', 'purge', 'purge', 'COM_ASSOCIATIONS_PURGE', false, false); - ToolbarHelper::custom('associations.clean', 'refresh', 'refresh', 'COM_ASSOCIATIONS_DELETE_ORPHANS', false, false); - } - + $toolbar->confirmButton('purge') + ->text('COM_ASSOCIATIONS_PURGE') + ->message(Text::plural('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT', (Text::_($this->extensionName) . ' > ' . Text::_($languageKey)))) + ->task('associations.purge'); + ToolbarHelper::custom('associations.clean', 'refresh', 'refresh', 'COM_ASSOCIATIONS_DELETE_ORPHANS', false, false); ToolbarHelper::preferences('com_associations'); } diff --git a/administrator/components/com_associations/tmpl/associations/default.php b/administrator/components/com_associations/tmpl/associations/default.php index 094fb0f380eb0..add65d9a203c4 100644 --- a/administrator/components/com_associations/tmpl/associations/default.php +++ b/administrator/components/com_associations/tmpl/associations/default.php @@ -29,8 +29,6 @@ 2 => 'icon-archive', ); -Text::script('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT', true); -HTMLHelper::_('script', 'com_associations/admin-associations-default.min.js', ['version' => 'auto', 'relative' => true]); ?>
@@ -147,7 +145,7 @@ - + pagination->getListFooter(); ?> diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index 14898e17551dd..1fb89ec1d232c 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -31,7 +31,7 @@ COM_ASSOCIATIONS_ITEMS="Items" COM_ASSOCIATIONS_NO_ASSOCIATION="There is no association for this language" COM_ASSOCIATIONS_NOTICE_NO_SELECTORS="Please select an Item Type and a reference language to view the associations." COM_ASSOCIATIONS_PURGE="Delete All Associations" -COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT="Are you sure you want to delete all associations? Confirming will permanently delete them!" +COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT="Are you sure you want to delete all associations concerning %s? Confirming will permanently delete them!" COM_ASSOCIATIONS_PURGE_FAILED="Failed to delete all associations." COM_ASSOCIATIONS_PURGE_NONE="There were no associations to delete." COM_ASSOCIATIONS_PURGE_SUCCESS="All associations have been deleted." diff --git a/build/media_source/com_associations/js/admin-associations-default.es6.js b/build/media_source/com_associations/js/admin-associations-default.es6.js deleted file mode 100644 index cf078ebdd53f1..0000000000000 --- a/build/media_source/com_associations/js/admin-associations-default.es6.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ -Joomla.submitbutton = (pressbutton) => { - if (pressbutton === 'associations.purge') { - // eslint-disable-next-line no-restricted-globals - if (confirm(Joomla.JText._('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT'))) { - Joomla.submitform(pressbutton); - } else { - return false; - } - } else { - Joomla.submitform(pressbutton); - } - - return true; -}; From 655f7bb930e3049faa04e8137bfb5ed18f986458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 27 May 2019 18:06:44 +0200 Subject: [PATCH 03/98] merge the Association- and the "Not Associated"-column together - picked code from Wang-Yu-Chao/gsoc18_automatic_multilingual_association@55d46a16b404876ba405aee07fec8168c24b05e6 -- remove column "Not Associated" from table -- removed now unused string -- removed parameter from function, as it is useless now --- remove all code using this parameter -- change color of the language-links --- grey (secondary) for not associated items --- green (success) for associated items --- .../Helper/AssociationsHelper.php | 20 +++---------------- .../tmpl/associations/default.php | 8 +------- .../language/en-GB/en-GB.com_associations.ini | 1 - 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 564e42d1aa61b..6c756166115af 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -211,13 +211,12 @@ private static function getExtensionRealName($extensionName) * @param integer $itemId Item id. * @param string $itemLanguage Item language code. * @param boolean $addLink True for adding edit links. False for just text. - * @param boolean $assocLanguages True for showing non associated content languages. False only languages with associations. * * @return string The language HTML * * @since 3.7.0 */ - public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true, $assocLanguages = true) + public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true) { // Get the associations list for this item. $items = self::getAssociationList($extensionName, $typeName, $itemId); @@ -239,19 +238,6 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId continue; } - // Don't show languages with associations, if we don't want to show them. - if ($assocLanguages && isset($items[$langCode])) - { - unset($items[$langCode]); - continue; - } - - // Don't show languages without associations, if we don't want to show them. - if (!$assocLanguages && !isset($items[$langCode])) - { - continue; - } - // Get html parameters. if (isset($items[$langCode])) { @@ -289,7 +275,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $additional = '' . Text::sprintf('COM_MENUS_MENU_SPRINTF', $menutype_title) . '
'; } - $labelClass = 'badge-secondary'; + $labelClass = 'badge-success'; $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; $allow = $canEditReference && self::allowEdit($extensionName, $typeName, $items[$langCode]['id']) @@ -303,7 +289,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $title = Text::_('COM_ASSOCIATIONS_NO_ASSOCIATION'); $additional = $addLink ? Text::_('COM_ASSOCIATIONS_ADD_NEW_ASSOCIATION') : ''; - $labelClass = 'badge-warning'; + $labelClass = 'badge-secondary'; $target = $langCode . ':0:add'; $allow = $canCreate; } diff --git a/administrator/components/com_associations/tmpl/associations/default.php b/administrator/components/com_associations/tmpl/associations/default.php index add65d9a203c4..f9b84d5a7589c 100644 --- a/administrator/components/com_associations/tmpl/associations/default.php +++ b/administrator/components/com_associations/tmpl/associations/default.php @@ -60,9 +60,6 @@ - - - typeFields['menutype'])) : ?> @@ -122,10 +119,7 @@ - extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout, false); ?> - - - extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout, true); ?> + extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout); ?> typeFields['menutype'])) : ?> diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index 1fb89ec1d232c..bbfdf191a5402 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -26,7 +26,6 @@ COM_ASSOCIATIONS_HEADING_ASSOCIATION="Associations" COM_ASSOCIATIONS_HEADING_MENUTYPE="Menu" COM_ASSOCIATIONS_HEADING_MENUTYPE_ASC="Menu ascending" COM_ASSOCIATIONS_HEADING_MENUTYPE_DESC="Menu descending" -COM_ASSOCIATIONS_HEADING_NO_ASSOCIATION="Not Associated" COM_ASSOCIATIONS_ITEMS="Items" COM_ASSOCIATIONS_NO_ASSOCIATION="There is no association for this language" COM_ASSOCIATIONS_NOTICE_NO_SELECTORS="Please select an Item Type and a reference language to view the associations." From 9cd69c009ef50f717bb633f1c8d534fb176c1a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 28 May 2019 13:37:35 +0200 Subject: [PATCH 04/98] Add fields for setting a masterlanguage This add two fields for setting a masterlanguage in the languagefilter plugin. To set these parameters correctly there has been added an onExtensionAfterSave event, because these parameters depends on others. --- .../en-GB/en-GB.plg_system_languagefilter.ini | 4 ++ .../Field/ContentsitelanguageField.php | 67 +++++++++++++++++++ .../system/languagefilter/languagefilter.php | 47 +++++++++++++ .../system/languagefilter/languagefilter.xml | 27 ++++++++ 4 files changed, 145 insertions(+) create mode 100644 plugins/system/languagefilter/Field/ContentsitelanguageField.php diff --git a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini index 20b7a152095df..e9b6cfef81c8b 100644 --- a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini +++ b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini @@ -12,6 +12,10 @@ PLG_SYSTEM_LANGUAGEFILTER_FIELD_DETECT_BROWSER_LABEL="Language Selection for new PLG_SYSTEM_LANGUAGEFILTER_FIELD_ITEM_ASSOCIATIONS_LABEL="Item Associations" PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LABEL="Add x-default Meta Tag" PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LANGUAGE_LABEL="x-default Language" +PLG_SYSTEM_LANGUAGEFILTER_MASTER_LANGUAGE_DESC="These settings apply for all multilingual associations. By setting an master language, the association states 'not associated', 'new', 'outdated', 'up-to-date' are set for translated items, depending on changes to items in the master language." +PLG_SYSTEM_LANGUAGEFILTER_MASTER_LANGUAGE_FIELD_GLOBAL_MASTER_LANGUAGE_LABEL="Global Master Language" +PLG_SYSTEM_LANGUAGEFILTER_MASTER_LANGUAGE_FIELD_USE_MASTER_LANGUAGE_LABEL="Set a Master Language?" +PLG_SYSTEM_LANGUAGEFILTER_MASTER_LANGUAGE_LABEL="Master Language" PLG_SYSTEM_LANGUAGEFILTER_OPTION_DEFAULT_LANGUAGE="Default frontend language" PLG_SYSTEM_LANGUAGEFILTER_FIELD_REMOVE_DEFAULT_PREFIX_LABEL="Remove URL Language Code" PLG_SYSTEM_LANGUAGEFILTER_OPTION_SESSION="Session" diff --git a/plugins/system/languagefilter/Field/ContentsitelanguageField.php b/plugins/system/languagefilter/Field/ContentsitelanguageField.php new file mode 100644 index 0000000000000..8355fefc8c092 --- /dev/null +++ b/plugins/system/languagefilter/Field/ContentsitelanguageField.php @@ -0,0 +1,67 @@ +get('site'); + $contentLanguages = LanguageHelper::getContentLanguages(array(0, 1)); + $options = array(); + + foreach ($contentLanguages as $langCode) + { + // Add the information to the language if it is the default site language + if ($langCode->lang_code == $defaultSiteLanguage) + { + $options[] = HTMLHelper::_('select.option', $langCode->lang_code, $langCode->title + . ' - ' . Text::_('PLG_SYSTEM_LANGUAGEFILTER_OPTION_DEFAULT_LANGUAGE') + ); + } + else + { + $options[] = HTMLHelper::_('select.option', $langCode->lang_code, $langCode->title); + } + } + + return $options; + } +} diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index 0452ef4515b8d..f06a2636d1f8c 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -960,4 +960,51 @@ private function getLanguageCookie() return $languageCode; } + + // Events for Masterlanguage: + + /** + * Before Saving extensions + * Method is called when an extension is going to be saved + * change parameters for master language because there depends on other parameters + * + * @param string $context The extension + * @param JTable $table DataBase Table object + * @param boolean $isNew If the extension is new or not + * + * @return void + * + * @since 4.0.0 + */ + public function onExtensionBeforeSave($context, $table, $isNew) + { + // get the params to save + $params = json_decode($table->params); + $tableElement = $table->element; + $pluginStatus = $table->enabled; + $itemAssocStatus = $params->item_associations; + + if ($context != 'com_plugins.plugin' && $tableElement != 'languagefilter') + { + return true; + } + + // if the plugin and the parameter item associations are enabled then set the correct value for the global master language + if($pluginStatus && $itemAssocStatus) + { + $globalMasterLanguage = ($params->use_master_language === '1') + ? $params->global_master_language + : ''; + $params->global_master_language = $globalMasterLanguage; + } + // reset parameters for master language + else + { + $params->use_master_language = ''; + $params->global_master_language = ''; + } + + return $table->params = json_encode($params); + } + } diff --git a/plugins/system/languagefilter/languagefilter.xml b/plugins/system/languagefilter/languagefilter.xml index fea021cbea836..e3f2df1aba38c 100644 --- a/plugins/system/languagefilter/languagefilter.xml +++ b/plugins/system/languagefilter/languagefilter.xml @@ -9,8 +9,10 @@ www.joomla.org 3.0.0 PLG_SYSTEM_LANGUAGEFILTER_XML_DESCRIPTION + Joomla\Plugin\System\Languagefilter languagefilter.php + Field en-GB.plg_system_languagefilter.ini @@ -112,6 +114,31 @@ +
+ + + + + + +
\ No newline at end of file From b74930cc4a99c4e966cbcaacfed71ecceb66e26d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Wed, 29 May 2019 15:36:50 +0200 Subject: [PATCH 05/98] save the master item in the associations table The master item is the one written in the language of the global master language. - New Column 'parent_id' for saving relationsship of items of an association. If an association contains no items with the masterlanguage (it may be not used) the value is -1. If an association contains an item with the masterlanguage, this is now the parent and is set with 0. The other items of this association get the id of the master item / parent. - Add new method to get the global master language parameter. - Change save-methods for the associations table concidering the new column - Add methods to change the master item in the associations table after saving the Languagefilter Plugin. - set global master language parameters in multi sample data --- .../com_categories/Model/CategoryModel.php | 9 +- .../components/com_menus/Model/ItemModel.php | 9 +- installation/sql/mysql/joomla.sql | 1 + installation/sql/postgresql/joomla.sql | 2 + installation/src/Model/LanguagesModel.php | 9 +- libraries/src/Language/Associations.php | 35 ++++ libraries/src/MVC/Model/AdminModel.php | 9 +- plugins/sampledata/multilang/multilang.php | 14 +- .../system/languagefilter/languagefilter.php | 161 ++++++++++++++++++ 9 files changed, 243 insertions(+), 6 deletions(-) diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index 399a539495e72..ba752d367d218 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -676,6 +676,10 @@ public function save($data) if (count($associations) > 1) { + // If there is an association item with the globalMasterLanguage, then get his id + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $masterID = $associations[$globalMasterLanguage] ?? ''; + // Adding new association for these items $key = md5(json_encode($associations)); $query->clear() @@ -683,7 +687,10 @@ public function save($data) foreach ($associations as $id) { - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key)); + // If there is no master item in this association, then reset the parent_id to -1 + // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. + $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; + $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($parentId)); } $db->setQuery($query); diff --git a/administrator/components/com_menus/Model/ItemModel.php b/administrator/components/com_menus/Model/ItemModel.php index 49b68ac75d161..456219dc37e5d 100644 --- a/administrator/components/com_menus/Model/ItemModel.php +++ b/administrator/components/com_menus/Model/ItemModel.php @@ -1539,6 +1539,10 @@ public function save($data) if (count($associations) > 1) { + // If there is an association item with the globalMasterLanguage, then get his id + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $masterID = $associations[$globalMasterLanguage] ?? ''; + // Adding new association for these items $key = md5(json_encode($associations)); $query->clear() @@ -1546,7 +1550,10 @@ public function save($data) foreach ($associations as $id) { - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key)); + // If there is no master item in this association, then reset the parent_id to -1 + // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. + $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; + $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($parentId)); } $db->setQuery($query); diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index 99f6256e51f9c..6a775e4060b56 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -107,6 +107,7 @@ CREATE TABLE IF NOT EXISTS `#__associations` ( `id` int(11) NOT NULL COMMENT 'A reference to the associated item.', `context` varchar(50) NOT NULL COMMENT 'The context of the associated item.', `key` char(32) NOT NULL COMMENT 'The key for the association computed from an md5 on associated ids.', + `parent_id` int(11) NOT NULL DEFAULT -1 COMMENT 'The parent master item of an association.', PRIMARY KEY (`context`,`id`), KEY `idx_key` (`key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index 16dcffd53e7d1..e29fcd6fa52d7 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -111,6 +111,7 @@ CREATE TABLE IF NOT EXISTS "#__associations" ( "id" int NOT NULL, "context" varchar(50) NOT NULL, "key" char(32) NOT NULL, + "parent_id" integer DEFAULT -1 NOT NULL, CONSTRAINT "#__associations_idx_context_id" PRIMARY KEY ("context", "id") ); CREATE INDEX "#__associations_idx_key" ON "#__associations" ("key"); @@ -118,6 +119,7 @@ CREATE INDEX "#__associations_idx_key" ON "#__associations" ("key"); COMMENT ON COLUMN "#__associations"."id" IS 'A reference to the associated item.'; COMMENT ON COLUMN "#__associations"."context" IS 'The context of the associated item.'; COMMENT ON COLUMN "#__associations"."key" IS 'The key for the association computed from an md5 on associated ids.'; +COMMENT ON COLUMN "#__associations"."parent_id" IS 'The parent master item of an association.'; -- -- Table structure for table `#__banners` diff --git a/installation/src/Model/LanguagesModel.php b/installation/src/Model/LanguagesModel.php index f2530e9d5e207..bc8d3fb196731 100644 --- a/installation/src/Model/LanguagesModel.php +++ b/installation/src/Model/LanguagesModel.php @@ -17,6 +17,7 @@ use Joomla\CMS\Form\Form; use Joomla\CMS\Installer\Installer; use Joomla\CMS\Installer\InstallerHelper; +use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Language; use Joomla\CMS\Language\LanguageHelper; use Joomla\CMS\Language\Text; @@ -1407,16 +1408,22 @@ public function addBlogMenuItem($itemLanguage, $categoryId) public function addAssociations($groupedAssociations) { $db = Factory::getDbo(); + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); foreach ($groupedAssociations as $context => $associations) { + // If there is an association item with the globalMasterLanguage, then get his id + $masterID = $associations[$globalMasterLanguage] ?? ''; $key = md5(json_encode($associations)); $query = $db->getQuery(true) ->insert('#__associations'); foreach ($associations as $language => $id) { - $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key)); + // If there is no master item in this association, then reset the parent_id to -1 + // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. + $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; + $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($parentId)); } $db->setQuery($query); diff --git a/libraries/src/Language/Associations.php b/libraries/src/Language/Associations.php index ee5a9130dacb1..2ec9d6cb867ea 100644 --- a/libraries/src/Language/Associations.php +++ b/libraries/src/Language/Associations.php @@ -172,4 +172,39 @@ public static function isEnabled() return $enabled; } + + /** + * Method to get the global master language parameter for associations. + * + * @return string empty if not set, lang_code otherwise + * + * @since 4.0 + */ + public static function getGlobalMasterLanguage() + { + // Flag to avoid doing multiple database queries. + static $tested = false; + + // Status of global master language parameter. + static $globalMasterLanguage = ''; + + if (self::isEnabled()) + { + // If already tested, don't test again. + if (!$tested) + { + $plugin = PluginHelper::getPlugin('system', 'languagefilter'); + + if (!empty($plugin)) + { + $params = new Registry($plugin->params); + $globalMasterLanguage = $params->get('global_master_language'); + } + + $tested = true; + } + } + + return $globalMasterLanguage ?? ''; + } } diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 136ee9bf97072..eb46a49f6d1f6 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -1355,6 +1355,10 @@ public function save($data) if (count($associations) > 1) { + // If there is an association item with the globalMasterLanguage, then get his id + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $masterID = $associations[$globalMasterLanguage] ?? ''; + // Adding new association for these items $key = md5(json_encode($associations)); $query = $db->getQuery(true) @@ -1362,7 +1366,10 @@ public function save($data) foreach ($associations as $id) { - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key)); + // If there is no master item in this association, then reset the parent_id to -1 + // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. + $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; + $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($parentId)); } $db->setQuery($query); diff --git a/plugins/sampledata/multilang/multilang.php b/plugins/sampledata/multilang/multilang.php index 2b234107f760a..1aa686c8a1c77 100644 --- a/plugins/sampledata/multilang/multilang.php +++ b/plugins/sampledata/multilang/multilang.php @@ -14,6 +14,7 @@ use Joomla\CMS\Extension\ExtensionHelper; use Joomla\CMS\Factory; use Joomla\CMS\Installer\Installer; +use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Language; use Joomla\CMS\Language\LanguageHelper; use Joomla\CMS\Language\Text; @@ -510,13 +511,16 @@ private function enablePlugin($pluginName) // Store language filter plugin parameters. if ($pluginName == 'plg_system_languagefilter') { + $currentDefaultLanguage = $this->app->get('language'); $params = '{' . '"detect_browser":"0",' . '"automatic_change":"1",' . '"item_associations":"1",' . '"remove_default_prefix":"0",' . '"lang_cookie":"0",' - . '"alternate_meta":"1"' + . '"alternate_meta":"1",' + . '"user_master_language":"1",' + . '"global_master_language":"' . $currentDefaultLanguage . '"' . '}'; $query ->clear() @@ -899,16 +903,22 @@ private function addBlogMenuItem($itemLanguage, $categoryId) private function addAssociations($groupedAssociations) { $db = Factory::getDbo(); + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); foreach ($groupedAssociations as $context => $associations) { + // If there is an association item with the globalMasterLanguage, then get his id + $masterID = $associations[$globalMasterLanguage] ?? ''; $key = md5(json_encode($associations)); $query = $db->getQuery(true) ->insert('#__associations'); foreach ($associations as $language => $id) { - $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key)); + // If there is no master item in this association, then reset the parent_id to -1 + // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. + $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; + $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($parentId)); } $db->setQuery($query); diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index f06a2636d1f8c..d41e7ee5583a9 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -1007,4 +1007,165 @@ public function onExtensionBeforeSave($context, $table, $isNew) return $table->params = json_encode($params); } + /** + * After save extensions + * Method is called when an extension has been saved + * + * @param string $context The extension + * @param JTable $table DataBase Table object + * @param boolean $isNew If the extension is new or not + * + * @return void + * + * @since 4.0.0 + */ + public function onExtensionAfterSave($context, $table, $isNew) + { + // get the params that have been saved + $params = json_decode($table->params); + $tableElement = $table->element; + + if ($context != 'com_plugins.plugin' && $tableElement != 'languagefilter') + { + return true; + } + + $this->_setMasterItem($params->global_master_language); + } + + /** + * Method to set the master item of an association as parent and the children get the parent id + * + * @param string $language The global master language + * + * @return void + * + * @since 4.0.0 + */ + private function _setMasterItem($language) + { + $db = Factory::getDbo(); + $masterLanguage = $language; + + // TODO add warning when master language changed + + // if there is no global masterlanguage set, set all parent_ids to -1 + if (!$masterLanguage) + { + $resetQuery = $db->getQuery(true) + ->update($db->quoteName('#__associations')) + ->set($db->quoteName('parent_id') . ' = ' . -1); + $db->setQuery($resetQuery); + + try + { + $db->execute(); + } + catch (ExecutionFailureException $e) + { + $this->_message .= Text::_(' , failed to update the master with his childs'); + + return; + } + } + else + { + // TODO Question? Maybe if the language hasn't changed it isn't necessary to run this again. But no possibility to check that? + + // get every different key + $keyQuery = $db->getQuery(true) + ->select($db->quoteName('key')) + ->from($db->quoteName('#__associations')) + ->group($db->quoteName('key')) + ->having('COUNT(*) > 1'); + $assocKeys = $db->setQuery($keyQuery)->loadColumn(); + + foreach ($assocKeys as $value) + { + //get the context of the association with the current key + $contextQuery = $db->getQuery(true) + ->select($db->quoteName('context')) + ->from($db->quoteName('#__associations')) + ->where($db->quoteName('key') . ' = ' . $db->quote($value)); + $assocContext = $db->setQuery($contextQuery)->loadResult(); + + // get the correct table to look in depending on the context + switch ($assocContext) + { + case 'com_content.item': + $fromTable = $db->quoteName('#__content', 'e'); + break; + + case 'com_menus.item' : + $fromTable = $db->quoteName('#__menu', 'e'); + break; + + case 'com_categories.item': + $fromTable = $db->quoteName('#__categories', 'e'); + break; + + case 'com_contact.item': + $fromTable = $db->quoteName('#__contact_details', 'e'); + break; + + case 'com_newsfeeds.item': + $fromTable = $db->quoteName('#__newsfeeds', 'e'); + break; + } + + // get items with the global master language + $subQuery = $db->getQuery(true) + ->select($db->quoteName('e.id')) + ->from($fromTable) + ->where($db->quoteName('e.language') . ' = ' . $db->quote($masterLanguage)); + + // get master id of an item that has the global master language + $masterQuery = $db->getQuery(true) + ->select($db->quoteName('id')) + ->from('#__associations') + ->where($db->quoteName('id') . ' IN (' . $subQuery . ')') + ->where($db->quoteName('key') . ' = ' . $db->quote($value)); + $masterId = $db->setQuery($masterQuery)->loadResult(); + + // Set the master item as parent + $query = $db->getQuery(true) + ->update($db->quoteName('#__associations')) + ->set($db->quoteName('parent_id') . ' = ' . 0) + ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('key') . ' = ' . $db->quote($value)); + $db->setQuery($query); + + try + { + $db->execute(); + } + catch (ExecutionFailureException $e) + { + $this->_message .= Text::_(' , failed to update the master with his childs'); + + return; + } + + // Set the master id to the children + $query = $db->getQuery(true) + ->update($db->quoteName('#__associations')) + ->set($db->quoteName('parent_id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('id') . ' <> ' . $db->quote($masterId)) + ->where($db->quoteName('key') . ' = ' . $db->quote($value)); + $db->setQuery($query); + + try + { + $db->execute(); + } + catch (ExecutionFailureException $e) + { + $this->_message .= Text::_(' , failed to update the master with his childs'); + + return; + } + + } + } + } } From eb72d74d063bbf6dfe0380bc466ea1d1112569b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Thu, 30 May 2019 18:46:40 +0200 Subject: [PATCH 06/98] change color of associations and center associations column After the colors in the association view have changed after the columns have been merged, they are now adjusted for the other lists. In addition, the association column has been centered in each list. --- .../components/com_associations/tmpl/associations/default.php | 4 ++-- .../com_categories/Service/HTML/AdministratorService.php | 2 +- .../components/com_categories/tmpl/categories/default.php | 4 ++-- .../com_contact/Service/HTML/AdministratorService.php | 2 +- .../components/com_contact/tmpl/contacts/default.php | 4 ++-- .../com_content/Service/HTML/AdministratorService.php | 2 +- .../components/com_content/tmpl/articles/default.php | 4 ++-- administrator/components/com_menus/Service/HTML/Menus.php | 2 +- .../com_newsfeeds/Service/HTML/AdministratorService.php | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/administrator/components/com_associations/tmpl/associations/default.php b/administrator/components/com_associations/tmpl/associations/default.php index 10cca0c3f0edd..fdc8b90436f4d 100644 --- a/administrator/components/com_associations/tmpl/associations/default.php +++ b/administrator/components/com_associations/tmpl/associations/default.php @@ -57,7 +57,7 @@ - + typeFields['menutype'])) : ?> @@ -118,7 +118,7 @@ - + extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout); ?> typeFields['menutype'])) : ?> diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index 2f7758819dcba..d2da46f039a2a 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -75,7 +75,7 @@ public function association($catid, $extension = 'com_content') { $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; $url = Route::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); - $classes = 'hasPopover badge badge-secondary'; + $classes = 'hasPopover badge badge-success'; $item->link = '' . $text . ''; diff --git a/administrator/components/com_categories/tmpl/categories/default.php b/administrator/components/com_categories/tmpl/categories/default.php index 1deb194cbebc6..0ef0defd9d035 100644 --- a/administrator/components/com_categories/tmpl/categories/default.php +++ b/administrator/components/com_categories/tmpl/categories/default.php @@ -112,7 +112,7 @@ assoc) : ?> - + @@ -237,7 +237,7 @@ escape($item->access_level); ?> assoc) : ?> - + association) : ?> id, $extension); ?> diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index 9afd50b7fab76..6c4e67becf9cf 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -79,7 +79,7 @@ public function association($contactid) $text = strtoupper($item->lang_sef); $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); - $classes = 'hasPopover badge badge-secondary'; + $classes = 'hasPopover badge badge-success'; $item->link = '' diff --git a/administrator/components/com_contact/tmpl/contacts/default.php b/administrator/components/com_contact/tmpl/contacts/default.php index 47791be7f0fbf..92d3713cb3c11 100644 --- a/administrator/components/com_contact/tmpl/contacts/default.php +++ b/administrator/components/com_contact/tmpl/contacts/default.php @@ -77,7 +77,7 @@ - + @@ -168,7 +168,7 @@ access_level; ?> - + association) : ?> id); ?> diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index 80a3178476155..011dd077b8e75 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -81,7 +81,7 @@ public function association($articleid) $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); - $classes = 'hasPopover badge badge-secondary'; + $classes = 'hasPopover badge badge-success'; $item->link = '
' diff --git a/administrator/components/com_content/tmpl/articles/default.php b/administrator/components/com_content/tmpl/articles/default.php index da807b6365c60..c456deb64f708 100644 --- a/administrator/components/com_content/tmpl/articles/default.php +++ b/administrator/components/com_content/tmpl/articles/default.php @@ -133,7 +133,7 @@ - + @@ -340,7 +340,7 @@ escape($item->access_level); ?> - + association) : ?> id); ?> diff --git a/administrator/components/com_menus/Service/HTML/Menus.php b/administrator/components/com_menus/Service/HTML/Menus.php index 79411d3542bec..0ca5863bba548 100644 --- a/administrator/components/com_menus/Service/HTML/Menus.php +++ b/administrator/components/com_menus/Service/HTML/Menus.php @@ -79,7 +79,7 @@ public function association($itemid) $text = strtoupper($item->lang_sef); $url = Route::_('index.php?option=com_menus&task=item.edit&id=' . (int) $item->id); $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('COM_MENUS_MENU_SPRINTF', $item->menu_title); - $classes = 'hasPopover badge badge-secondary'; + $classes = 'hasPopover badge badge-success'; $item->link = '
' diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index 34da73acda15f..b35d18d7b95fa 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -78,7 +78,7 @@ public function association($newsfeedid) $text = strtoupper($item->lang_sef); $url = Route::_('index.php?option=com_newsfeeds&task=newsfeed.edit&id=' . (int) $item->id); $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); - $classes = 'hasPopover badge badge-secondary'; + $classes = 'hasPopover badge badge-success'; $item->link = '
' From cc03c4874fd4934cb13035a93851d19df87a3312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Thu, 30 May 2019 18:51:41 +0200 Subject: [PATCH 07/98] add masterlanguage information to the language select box If a global master language has been set, it is displayed as info in the Language select box , so that it is recognizable which master language has been set. --- .../Field/ContentmasterlanguageField.php | 69 +++++++++++++++++++ .../forms/filter_associations.xml | 3 +- .../language/en-GB/en-GB.com_associations.ini | 1 + 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 administrator/components/com_associations/Field/ContentmasterlanguageField.php diff --git a/administrator/components/com_associations/Field/ContentmasterlanguageField.php b/administrator/components/com_associations/Field/ContentmasterlanguageField.php new file mode 100644 index 0000000000000..d6cbf997e36e5 --- /dev/null +++ b/administrator/components/com_associations/Field/ContentmasterlanguageField.php @@ -0,0 +1,69 @@ +lang_code == $globalMasterLanguage) + { + $options[] = HTMLHelper::_('select.option', $langCode->lang_code, $langCode->title . ' - ' + . Text::_('COM_ASSOCIATIONS_MASTER_LANGUAGE') + ); + } + else + { + $options[] = HTMLHelper::_('select.option', $langCode->lang_code, $langCode->title); + } + } + + return $options; + } +} diff --git a/administrator/components/com_associations/forms/filter_associations.xml b/administrator/components/com_associations/forms/filter_associations.xml index d865248ba313d..155a7a0abe78c 100644 --- a/administrator/components/com_associations/forms/filter_associations.xml +++ b/administrator/components/com_associations/forms/filter_associations.xml @@ -10,8 +10,7 @@ diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index bbfdf191a5402..28e4fe2e54459 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -27,6 +27,7 @@ COM_ASSOCIATIONS_HEADING_MENUTYPE="Menu" COM_ASSOCIATIONS_HEADING_MENUTYPE_ASC="Menu ascending" COM_ASSOCIATIONS_HEADING_MENUTYPE_DESC="Menu descending" COM_ASSOCIATIONS_ITEMS="Items" +COM_ASSOCIATIONS_MASTER_LANGUAGE="Master" COM_ASSOCIATIONS_NO_ASSOCIATION="There is no association for this language" COM_ASSOCIATIONS_NOTICE_NO_SELECTORS="Please select an Item Type and a reference language to view the associations." COM_ASSOCIATIONS_PURGE="Delete All Associations" From b669d7b4243f16b0e6402b353251deb48bb3c4ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Thu, 30 May 2019 22:47:25 +0200 Subject: [PATCH 08/98] fix the toolbar button where variables have to be checked if they are set or not --- .../com_associations/View/Associations/HtmlView.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_associations/View/Associations/HtmlView.php b/administrator/components/com_associations/View/Associations/HtmlView.php index 9ed6a6a459fb4..c60f539f3a04c 100644 --- a/administrator/components/com_associations/View/Associations/HtmlView.php +++ b/administrator/components/com_associations/View/Associations/HtmlView.php @@ -255,7 +255,11 @@ protected function addToolbar() { $toolbar->confirmButton('purge') ->text('COM_ASSOCIATIONS_PURGE') - ->message(Text::plural('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT', (Text::_($this->extensionName) . ' > ' . Text::_($languageKey)))) + ->message( + (isset($this->extensionName) && isset($languageKey)) + ? Text::plural('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT', (Text::_($this->extensionName) . ' > ' . Text::_($languageKey))) + : Text::_('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT') + ) ->task('associations.purge'); ToolbarHelper::custom('associations.clean', 'refresh', 'refresh', 'COM_ASSOCIATIONS_DELETE_ORPHANS', false, false); ToolbarHelper::preferences('com_associations'); From d834ab6fdc1339555ec5c48e93312e72c1664846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Thu, 30 May 2019 23:04:19 +0200 Subject: [PATCH 09/98] center and widen the association column also in the associations modal --- .../components/com_associations/tmpl/associations/modal.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_associations/tmpl/associations/modal.php b/administrator/components/com_associations/tmpl/associations/modal.php index 7488b5ad67ccb..18e2a9689e1cf 100644 --- a/administrator/components/com_associations/tmpl/associations/modal.php +++ b/administrator/components/com_associations/tmpl/associations/modal.php @@ -75,7 +75,7 @@ - + typeFields['menutype'])) : ?> @@ -134,7 +134,7 @@ - + association) : ?> extensionName, $this->typeName, (int) $item->id, $item->language, false, false); ?> From 391e1a09d5d021591a4d0192c896c135322d63f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Fri, 31 May 2019 13:47:32 +0200 Subject: [PATCH 10/98] display the master-child associations in the list views In order to display the Master-Child relationship of the associations in the lists, the layout was adapted. So now all children of an association are displayed, if the item in the row is a master item. Otherwise, only the current child-item is displayed with its master item, since there is no direct relationship between the children. In addition, the links of the association items in the Associations View have been adjusted so that the reference is now oriented to the master item and target to the children. --- .../Helper/AssociationsHelper.php | 144 +++++++++++++++--- .../Service/HTML/AdministratorService.php | 38 ++++- .../Service/HTML/AdministratorService.php | 37 ++++- .../Service/HTML/AdministratorService.php | 36 ++++- .../com_menus/Service/HTML/Menus.php | 38 ++++- .../Service/HTML/AdministratorService.php | 37 ++++- .../templates/atum/scss/template.scss | 20 ++- layouts/joomla/content/associations.php | 24 ++- libraries/src/Language/Associations.php | 14 +- .../system/languagefilter/languagefilter.xml | 5 +- 10 files changed, 341 insertions(+), 52 deletions(-) diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 6c756166115af..bec1cae7cd9c5 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -16,6 +16,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\LanguageHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; @@ -218,6 +219,8 @@ private static function getExtensionRealName($extensionName) */ public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true) { + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + // Get the associations list for this item. $items = self::getAssociationList($extensionName, $typeName, $itemId); @@ -232,17 +235,38 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId // Create associated items list. foreach ($languages as $langCode => $language) { - // Don't do for the reference language. - if ($langCode == $itemLanguage) + // Don't do for the reference language, when there is no master language set + if ($langCode == $itemLanguage && !$globalMasterLanguage) { continue; } - // Get html parameters. + // Get html parameters for associated items if (isset($items[$langCode])) { - $title = $items[$langCode][$titleFieldName]; - $additional = ''; + if ($globalMasterLanguage) + { + // Get id of the master item + if ($itemLanguage === $globalMasterLanguage) + { + $masterId = $itemId; + } + else + { + // Don't display any other children to the child item + if (($langCode !== $globalMasterLanguage) && ($langCode !== $itemLanguage)) + { + unset($items[$langCode]); + continue; + } + + // Get id of the master item + $masterId = self::getGlobalMasterId($extensionName, $typeName, $itemId); + } + } + + $title = $items[$langCode][$titleFieldName]; + $additional = ''; if (isset($items[$langCode]['catid'])) { @@ -275,23 +299,69 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $additional = '' . Text::sprintf('COM_MENUS_MENU_SPRINTF', $menutype_title) . '
'; } - $labelClass = 'badge-success'; - $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; - $allow = $canEditReference - && self::allowEdit($extensionName, $typeName, $items[$langCode]['id']) - && self::canCheckinItem($extensionName, $typeName, $items[$langCode]['id']); + $labelClass = 'badge-success'; + $languageTitle = $language->title; + $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; + $allow = $canEditReference + && self::allowEdit($extensionName, $typeName, $items[$langCode]['id']) + && self::canCheckinItem($extensionName, $typeName, $items[$langCode]['id']); $additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : ''; + + + if ($globalMasterLanguage) + { + if ($globalMasterLanguage === $langCode) + { + $labelClass .= ' master-item'; + $languageTitle = $language->title . ' - ' . Text::_('COM_ASSOCIATIONS_MASTER_LANGUAGE'); + + if ($globalMasterLanguage === $itemLanguage) + { + $target = ''; + } + else + { + $target = $itemLanguage . ':' . $itemId . ':edit'; + } + } + } } + // Get html parameters for not associated items else { + // Don't display any other children to the child item + if ($globalMasterLanguage && ($itemLanguage != $globalMasterLanguage) + && ($langCode != $itemLanguage) + && ($langCode != $globalMasterLanguage)) + { + continue; + } + $items[$langCode] = array(); - $title = Text::_('COM_ASSOCIATIONS_NO_ASSOCIATION'); - $additional = $addLink ? Text::_('COM_ASSOCIATIONS_ADD_NEW_ASSOCIATION') : ''; - $labelClass = 'badge-secondary'; - $target = $langCode . ':0:add'; - $allow = $canCreate; + $title = Text::_('COM_ASSOCIATIONS_NO_ASSOCIATION'); + $additional = $addLink ? Text::_('COM_ASSOCIATIONS_ADD_NEW_ASSOCIATION') : ''; + $labelClass = 'badge-secondary'; + $target = $langCode . ':0:add'; + $allow = $canCreate; + $languageTitle = $language->title; + + if ($globalMasterLanguage) + { + if ($globalMasterLanguage === $langCode) + { + $labelClass .= ' master-item'; + $languageTitle = $language->title . ' - ' . Text::_('COM_ASSOCIATIONS_MASTER_LANGUAGE'); + $target = ''; + } + + // Change target, when there is no association with the global master language for the child item + if ($globalMasterLanguage !== $itemLanguage) + { + $target = $globalMasterLanguage . ':0:add'; + } + } } // Generate item Html. @@ -301,7 +371,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId 'layout' => 'edit', 'itemtype' => $extensionName . '.' . $typeName, 'task' => 'association.edit', - 'id' => $itemId, + 'id' => $masterId ?? $itemId, 'target' => $target, ); @@ -312,9 +382,16 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $tooltip = htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '

' . $additional; $classes = 'hasPopover badge ' . $labelClass; - $items[$langCode]['link'] = '
' - . $text . ''; + $items[$langCode]['link'] = '' + . $text . ''; + + // Reorder the array, so the master item gets to the first place + if ($langCode === $globalMasterLanguage) + { + $items = array('master' => $items[$langCode]) + $items; + unset($items[$langCode]); + } } HTMLHelper::_('bootstrap.popover'); @@ -411,6 +488,7 @@ public static function getSupportedExtension($extensionName) $languageKey = $typeName; $typeNameExploded = explode('.', $typeName); + if (array_pop($typeNameExploded) === 'category') { $languageKey = strtoupper($extensionName) . '_CATEGORIES'; @@ -685,4 +763,32 @@ public static function getLanguagefilterPluginId() return $result; } + + /** + * Get the associated master item id from a child element. + * + * @param string $extensionName Extension Name + * @param string $typeName ItemType + * @param integer $itemId Item id + * + * @return integer $masterElementId The id of the associated master item + * + * @since 4.0 + */ + public static function getGlobalMasterId($extensionName, $typeName, $itemId) + { + $db = Factory::getDbo(); + + $context = ($typeName === 'category') ? 'com_categories.item' : $extensionName . '.item'; + + $parentQuery = $db->getQuery(true) + ->select($db->quoteName('parent_id')) + ->from($db->quoteName('#__associations')) + ->where($db->quoteName('id') . ' = ' . $db->quote($itemId)) + ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + $masterId = $db->setQuery($parentQuery)->loadResult(); + + return (int) $masterId; + + } } diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index d2da46f039a2a..8c0fe099d79e2 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -13,6 +13,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Associations; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; @@ -40,6 +41,7 @@ public function association($catid, $extension = 'com_content') { // Defaults $html = ''; + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); // Get the associations if ($associations = CategoriesHelper::getAssociations($catid, $extension)) @@ -53,9 +55,15 @@ public function association($catid, $extension = 'com_content') ->select('l.sef as lang_sef') ->select('l.lang_code') ->from('#__categories as c') - ->where('c.id IN (' . implode(',', array_values($associations)) . ')') - ->where('c.id != ' . $catid) - ->join('LEFT', '#__languages as l ON c.language=l.lang_code') + ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); + + // Don't get the id of the item itself when there is no master language used + if (!$globalMasterLanguage) + { + $query->where('c.id != ' . $catid); + } + + $query->join('LEFT', '#__languages as l ON c.language=l.lang_code') ->select('l.image') ->select('l.title as language_title'); $db->setQuery($query); @@ -69,16 +77,38 @@ public function association($catid, $extension = 'com_content') throw new \Exception($e->getMessage(), 500, $e); } + // Check whether the current article is written in the global master language. + $masterElement = ($globalMasterLanguage && $items[$catid]->lang_code === $globalMasterLanguage) ? true : false; + if ($items) { - foreach ($items as &$item) + foreach ($items as $key => &$item) { + // Don't continue for master, because it has been set here before + if ($key === 'master') + { + continue; + } + + // Don't display other children if the current item is a child of the master language. + if ($key !== $catid && $globalMasterLanguage !== $item->lang_code && !$masterElement && $globalMasterLanguage) + { + unset($items[$key]); + } + $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; $url = Route::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); $classes = 'hasPopover badge badge-success'; $item->link = '' . $text . ''; + + // Reorder the array, so the master item gets to the first place + if ($item->lang_code === $globalMasterLanguage) + { + $items = array('master' => $items[$key]) + $items; + unset($items[$key]); + } } } diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index 6c4e67becf9cf..e626eae27e67c 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -39,6 +39,7 @@ public function association($contactid) { // Defaults $html = ''; + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); // Get the associations if ($associations = Associations::getAssociations('com_contact', '#__contact_details', 'com_contact.item', $contactid)) @@ -56,9 +57,15 @@ public function association($contactid) ->from('#__contact_details as c') ->select('cat.title as category_title') ->join('LEFT', '#__categories as cat ON cat.id=c.catid') - ->where('c.id IN (' . implode(',', array_values($associations)) . ')') - ->where('c.id != ' . $contactid) - ->join('LEFT', '#__languages as l ON c.language=l.lang_code') + ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); + + // Don't get the id of the item itself when there is no master language used + if (!$globalMasterLanguage) + { + $query->where('c.id != ' . $contactid); + } + + $query->join('LEFT', '#__languages as l ON c.language=l.lang_code') ->select('l.image') ->select('l.title as language_title'); $db->setQuery($query); @@ -72,10 +79,25 @@ public function association($contactid) throw new \Exception($e->getMessage(), 500, $e); } + // Check whether the current article is written in the global master language. + $masterElement = ($globalMasterLanguage && $items[$contactid]->lang_code === $globalMasterLanguage) ? true : false; + if ($items) { - foreach ($items as &$item) + foreach ($items as $key => &$item) { + // Don't continue for master, because it has been set here before + if ($key === 'master') + { + continue; + } + + // Don't display other children if the current item is a child of the master language. + if ($key !== $contactid && $globalMasterLanguage !== $item->lang_code && !$masterElement && $globalMasterLanguage) + { + unset($items[$key]); + } + $text = strtoupper($item->lang_sef); $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); @@ -84,6 +106,13 @@ public function association($contactid) $item->link = '' . $text . ''; + + // Reorder the array, so the master item gets to the first place + if ($item->lang_code === $globalMasterLanguage) + { + $items = array('master' => $items[$key]) + $items; + unset($items[$key]); + } } } diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index 011dd077b8e75..e30a6d5fa0280 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -40,6 +40,7 @@ public function association($articleid) { // Defaults $html = ''; + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); // Get the associations if ($associations = Associations::getAssociations('com_content', '#__content', 'com_content.item', $articleid)) @@ -58,9 +59,15 @@ public function association($articleid) ->from('#__content as c') ->select('cat.title as category_title') ->join('LEFT', '#__categories as cat ON cat.id=c.catid') - ->where('c.id IN (' . implode(',', array_values($associations)) . ')') - ->where('c.id != ' . $articleid) - ->join('LEFT', '#__languages as l ON c.language=l.lang_code') + ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); + + // Don't get the id of the item itself when there is no master language used + if (!$globalMasterLanguage) + { + $query->where('c.id != ' . $articleid); + } + + $query->join('LEFT', '#__languages as l ON c.language=l.lang_code') ->select('l.image') ->select('l.title as language_title'); $db->setQuery($query); @@ -74,10 +81,24 @@ public function association($articleid) throw new \Exception($e->getMessage(), 500, $e); } + // Check whether the current article is written in the global master language. + $masterElement = ($globalMasterLanguage && $items[$articleid]->lang_code === $globalMasterLanguage) ? true : false; + if ($items) { - foreach ($items as &$item) + foreach ($items as $key => &$item) { + // Don't continue for master, because it has been set here before + if ($key === 'master') { + continue; + } + + // Don't display other children if the current item is a child of the master language. + if (($key !== $articleid) && ($globalMasterLanguage !== $item->lang_code) && !$masterElement && $globalMasterLanguage) + { + unset($items[$key]); + } + $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); @@ -86,6 +107,13 @@ public function association($articleid) $item->link = '' . $text . ''; + + // Reorder the array, so the master item gets to the first place + if ($item->lang_code === $globalMasterLanguage) + { + $items = array('master' => $items[$key]) + $items; + unset($items[$key]); + } } } diff --git a/administrator/components/com_menus/Service/HTML/Menus.php b/administrator/components/com_menus/Service/HTML/Menus.php index 0ca5863bba548..1821922ca6a37 100644 --- a/administrator/components/com_menus/Service/HTML/Menus.php +++ b/administrator/components/com_menus/Service/HTML/Menus.php @@ -13,6 +13,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; @@ -43,6 +44,7 @@ public function association($itemid) { // Defaults $html = ''; + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); // Get the associations if ($associations = MenusHelper::getAssociations($itemid)) @@ -55,9 +57,15 @@ public function association($itemid) ->select('mt.title as menu_title') ->from('#__menu as m') ->join('LEFT', '#__menu_types as mt ON mt.menutype=m.menutype') - ->where('m.id IN (' . implode(',', array_values($associations)) . ')') - ->where('m.id != ' . $itemid) - ->join('LEFT', '#__languages as l ON m.language=l.lang_code') + ->where('m.id IN (' . implode(',', array_values($associations)) . ')'); + + // Don't get the id of the item itself when there is no master language used + if (!$globalMasterLanguage) + { + $query->where('m.id != ' . $itemid); + } + + $query->join('LEFT', '#__languages as l ON m.language=l.lang_code') ->select('l.image') ->select('l.title as language_title'); $db->setQuery($query); @@ -71,11 +79,26 @@ public function association($itemid) throw new \Exception($e->getMessage(), 500); } + // Check whether the current article is written in the global master language. + $masterElement = ($globalMasterLanguage && $items[$itemid]->lang_code === $globalMasterLanguage) ? true : false; + // Construct html if ($items) { - foreach ($items as &$item) + foreach ($items as $key => &$item) { + // Don't continue for master, because it has been set here before + if ($key === 'master') + { + continue; + } + + // Don't display other children if the current item is a child of the master language. + if ($key !== $itemid && $globalMasterLanguage !== $item->lang_code && !$masterElement && $globalMasterLanguage) + { + unset($items[$key]); + } + $text = strtoupper($item->lang_sef); $url = Route::_('index.php?option=com_menus&task=item.edit&id=' . (int) $item->id); $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('COM_MENUS_MENU_SPRINTF', $item->menu_title); @@ -84,6 +107,13 @@ public function association($itemid) $item->link = '' . $text . ''; + + // Reorder the array, so the master item gets to the first place + if ($item->lang_code === $globalMasterLanguage) + { + $items = array('master' => $items[$key]) + $items; + unset($items[$key]); + } } } diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index b35d18d7b95fa..bdb2519264a2c 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -38,6 +38,7 @@ public function association($newsfeedid) { // Defaults $html = ''; + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); // Get the associations if ($associations = Associations::getAssociations('com_newsfeeds', '#__newsfeeds', 'com_newsfeeds.item', $newsfeedid)) @@ -55,9 +56,15 @@ public function association($newsfeedid) ->from('#__newsfeeds as c') ->select('cat.title as category_title') ->join('LEFT', '#__categories as cat ON cat.id=c.catid') - ->where('c.id IN (' . implode(',', array_values($associations)) . ')') - ->where('c.id != ' . $newsfeedid) - ->join('LEFT', '#__languages as l ON c.language=l.lang_code') + ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); + + // Don't get the id of the item itself when there is no master language used + if (!$globalMasterLanguage) + { + $query->where('c.id != ' . $newsfeedid); + } + + $query->join('LEFT', '#__languages as l ON c.language=l.lang_code') ->select('l.image') ->select('l.title as language_title'); $db->setQuery($query); @@ -71,10 +78,25 @@ public function association($newsfeedid) throw new \Exception($e->getMessage(), 500); } + // Check whether the current article is written in the global master language. + $masterElement = ($globalMasterLanguage && $items[$newsfeedid]->lang_code === $globalMasterLanguage) ? true : false; + if ($items) { - foreach ($items as &$item) + foreach ($items as $key => &$item) { + // Don't continue for master, because it has been set here before + if ($key === 'master') + { + continue; + } + + // Don't display other children if the current item is a child of the master language. + if ($key !== $newsfeedid && $globalMasterLanguage !== $item->lang_code && !$masterElement && $globalMasterLanguage) + { + unset($items[$key]); + } + $text = strtoupper($item->lang_sef); $url = Route::_('index.php?option=com_newsfeeds&task=newsfeed.edit&id=' . (int) $item->id); $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); @@ -83,6 +105,13 @@ public function association($newsfeedid) $item->link = '' . $text . ''; + + // Reorder the array, so the master item gets to the first place + if ($item->lang_code === $globalMasterLanguage) + { + $items = array('master' => $items[$key]) + $items; + unset($items[$key]); + } } } diff --git a/administrator/templates/atum/scss/template.scss b/administrator/templates/atum/scss/template.scss index 2191617a84f60..9ab3a3992d71a 100644 --- a/administrator/templates/atum/scss/template.scss +++ b/administrator/templates/atum/scss/template.scss @@ -104,11 +104,23 @@ // Multilingual associations specific .item-associations { padding: 0; -} + position: relative; + margin-bottom: 0; + + li, ul { + display: inline-block; + list-style: none; + padding: 0; + } -.item-associations li { - display: inline-block; - list-style: none; + hr { + margin-top: 0.2rem; + margin-bottom: 0.2rem; + } + + .master-language > a { + border-radius: 0; + } } // Quickicon specific diff --git a/layouts/joomla/content/associations.php b/layouts/joomla/content/associations.php index 9bd8cd3fa1138..ff8f2c3d0695d 100644 --- a/layouts/joomla/content/associations.php +++ b/layouts/joomla/content/associations.php @@ -13,10 +13,26 @@ if (!empty($items)) : ?>
    - $item) : ?> -
  • - link; ?> + +
  • + link; ?> +
    +
      + $item) : ?> + +
    • + link; ?> +
    • + + +
  • - + + $item) : ?> +
  • + link; ?> +
  • + +
diff --git a/libraries/src/Language/Associations.php b/libraries/src/Language/Associations.php index 2ec9d6cb867ea..07de0d62a0ce2 100644 --- a/libraries/src/Language/Associations.php +++ b/libraries/src/Language/Associations.php @@ -42,6 +42,8 @@ class Associations public static function getAssociations($extension, $tablename, $context, $id, $pk = 'id', $aliasField = 'alias', $catField = 'catid', $advClause = array()) { + $globalMasterLanguage = self::getGlobalMasterLanguage(); + // To avoid doing duplicate database queries. static $multilanguageAssociations = array(); @@ -125,11 +127,19 @@ public static function getAssociations($extension, $tablename, $context, $id, $p { foreach ($items as $tag => $item) { - // Do not return itself as result - if ((int) $item->{$pk} !== $id) + if ($globalMasterLanguage) { + // If a global master language is set, we need all items of an associations $multilanguageAssociations[$queryKey][$tag] = $item; } + else + { + // Do not return itself as result + if ((int) $item->{$pk} !== $id) + { + $multilanguageAssociations[$queryKey][$tag] = $item; + } + } } } } diff --git a/plugins/system/languagefilter/languagefilter.xml b/plugins/system/languagefilter/languagefilter.xml index e3f2df1aba38c..d89fd521db9de 100644 --- a/plugins/system/languagefilter/languagefilter.xml +++ b/plugins/system/languagefilter/languagefilter.xml @@ -136,9 +136,8 @@ label="PLG_SYSTEM_LANGUAGEFILTER_MASTER_LANGUAGE_FIELD_GLOBAL_MASTER_LANGUAGE_LABEL" showon="item_associations:1[AND]use_master_language:1" addfieldprefix="Joomla\Plugin\System\Languagefilter\Field" - > - + /> - \ No newline at end of file + From 6812d9925970422f96c4f6aac2fc108f14366c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 3 Jun 2019 22:33:26 +0200 Subject: [PATCH 11/98] add masterlanguage as default to language select box --- .../com_associations/Model/AssociationsModel.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 631cca3ee71cf..15d3132dec054 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -13,6 +13,7 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; +use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\CMS\MVC\Model\ListModel; @@ -80,8 +81,9 @@ protected function populateState($ordering = 'ordering', $direction = 'asc') $forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd'); $forcedItemType = $app->input->get('forcedItemType', '', 'string'); - // Set default itemtype and default language to default site language - $defaultLanguage = ComponentHelper::getParams('com_languages')->get('site'); + // Set language select box to default site language or if set to the master language as default. + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $defaultLanguage = $globalMasterLanguage ?? ComponentHelper::getParams('com_languages')->get('site'); $defaultItemType = 'com_content.article'; // Adjust the context to support modal layouts. @@ -107,9 +109,7 @@ protected function populateState($ordering = 'ordering', $direction = 'asc') $this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string')); $this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'cmd')); - $this->setState('filter.category_id', - $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '', 'cmd') - ); + $this->setState('filter.category_id', $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '', 'cmd')); $this->setState('filter.menutype', $this->getUserStateFromRequest($this->context . '.filter.menutype', 'filter_menutype', '', 'string')); $this->setState('filter.access', $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', '', 'string')); $this->setState('filter.level', $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level', '', 'cmd')); From 149597797501706b7173aeb859489fabac688fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sat, 8 Jun 2019 17:25:59 +0200 Subject: [PATCH 12/98] Add modified date of a master item to the associations table This adds a new column "assocParams" to the association table where the modified date of the master item is stored. The column for the master item always gets its latest modified date, its children get the modified date when the association is created. The table of menu items does not yet have a modified date, so the column remains empty. Also, a new AssociationsHelperClass is added for all Masterlanguage matters. --- .../Helper/MasterAssociationsHelper.php | 189 ++++++++++++++++++ .../com_categories/Model/CategoryModel.php | 20 +- .../components/com_menus/Model/ItemModel.php | 2 +- installation/sql/mysql/joomla.sql | 1 + installation/sql/postgresql/joomla.sql | 1 + installation/src/Model/LanguagesModel.php | 2 +- libraries/src/MVC/Model/AdminModel.php | 25 ++- plugins/sampledata/multilang/multilang.php | 2 +- .../system/languagefilter/languagefilter.php | 29 ++- 9 files changed, 253 insertions(+), 18 deletions(-) create mode 100644 administrator/components/com_associations/Helper/MasterAssociationsHelper.php diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php new file mode 100644 index 0000000000000..29d94e80659c5 --- /dev/null +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -0,0 +1,189 @@ +getQuery(true) + ->select($db->quoteName('parent_id')) + ->from($db->quoteName('#__associations')) + ->where($db->quoteName('id') . ' = ' . $db->quote($itemId)) + ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + $masterId = $db->setQuery($parentQuery)->loadResult(); + + return (int) $masterId; + + } + + /** + * Method to get associated params of the master item. + * + * @param array $associations the associations to be saved. + * + * @param string $context the association context + * + * @return array associations with params + * + */ + public static function getAssociationsParams($associations, $context) + { + $db = Factory::getDbo(); + + foreach ($associations as $langCode => $id) + { + if(is_array($id)) { + $id = $id['id']; + } + $query = $db->getQuery(true) + ->select($db->quoteName('assocParams')) + ->from($db->quoteName('#__associations')) + ->where($db->quoteName('id') . ' = ' . $db->quote($id)) + ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + $db->setQuery($query); + $param = $db->loadResult(); + $assocParams[$id] = $param; + } + + return $assocParams; + } + + /** + * @param integer $id Item id + * @param integer $dataId Item id of an item that is going to be saved + * @param integer $masterId + * @param string $masterModified th + * @param array $associationsParams modified date to associated items + * @param string $old_key the old association key + * + * @return array parent id and modified date + */ + public static function getMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $old_key) { + + if ($masterId) + { + // For the master item + if ($masterId === $id) + { + $parentId = 0; + // set always the last modified date + $parentModified = $masterModified ?? null; + } + // For the children + else + { + $parentId = $masterId; + + if (!$old_key) + { + // Add modified date from master to new associated item + if ($dataId === $id) + { + $parentModified = $masterModified ?? null; + } + else + { + // Set old modified date from master to existing associated child if not empty + $parentModified = empty($associationsParams[$id]) ? $masterModified : $associationsParams[$id]; + } + } + else + { + // if modified date isn't set to the child item set it with current modified date from master + $parentModified = empty($associationsParams[$id]) ? $masterModified : $associationsParams[$id]; + } + } + } + // default values + else + { + $parentId = -1; + $parentModified = null; + } + + return [$parentId, $parentModified]; + } + + /** + * Get the latest modified date of an master item + * + * @param integer $masterId Id of the master item + * @param string $table The table name where the item exists + * + * @return string The modified date of the master item + */ + public static function getMasterModifiedDate($masterId, $table) + { + $db = Factory::getDbo(); + + if ($table === '#__categories') + { + $modifiedColumn = 'modified_time'; + } + else + { + $modifiedColumn = 'modified'; + } + + if ($masterId) + { + $masterDateQuery = $db->getQuery(true) + ->select($db->quoteName($modifiedColumn)) + ->from($db->quoteName($table)) + ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); + $db->setQuery($masterDateQuery); + $masterModified = $db->loadResult(); + + return $masterModified; + } + + return $masterModified ?? ''; + } +} \ No newline at end of file diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index ba752d367d218..12ab57cdbef98 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -27,6 +27,7 @@ use Joomla\CMS\MVC\Model\AdminModel; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\UCM\UCMType; +use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; use Joomla\Registry\Registry; use Joomla\String\StringHelper; @@ -630,6 +631,9 @@ public function save($data) Factory::getApplication()->enqueueMessage(Text::_('COM_CATEGORIES_ERROR_ALL_LANGUAGE_ASSOCIATED'), 'notice'); } + // Get association params before they get deleted + $associationsParams = MasterAssociationsHelper::getAssociationsParams($associations, $this->associationsContext); + // Get associationskey for edited item $db = $this->getDbo(); $query = $db->getQuery(true) @@ -678,7 +682,12 @@ public function save($data) { // If there is an association item with the globalMasterLanguage, then get his id $globalMasterLanguage = Associations::getGlobalMasterLanguage(); - $masterID = $associations[$globalMasterLanguage] ?? ''; + $masterId = $associations[$globalMasterLanguage] ?? ''; + // Id of the saved item + $dataId = (int) $table->id; + + // Get the modified date of master item + $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName()); // Adding new association for these items $key = md5(json_encode($associations)); @@ -687,10 +696,11 @@ public function save($data) foreach ($associations as $id) { - // If there is no master item in this association, then reset the parent_id to -1 - // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. - $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($parentId)); + $masterValues = MasterAssociationsHelper::getMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $oldKey); + $parentId = $masterValues[0]; + $parentModified = $masterValues[1]; + + $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($parentId) . ',' . $db->quote($parentModified)); } $db->setQuery($query); diff --git a/administrator/components/com_menus/Model/ItemModel.php b/administrator/components/com_menus/Model/ItemModel.php index 456219dc37e5d..ec1e2b27fdbb9 100644 --- a/administrator/components/com_menus/Model/ItemModel.php +++ b/administrator/components/com_menus/Model/ItemModel.php @@ -1553,7 +1553,7 @@ public function save($data) // If there is no master item in this association, then reset the parent_id to -1 // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($parentId)); + $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($parentId) . ',' . $db->quote('')); } $db->setQuery($query); diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index 8197343cd02b6..f88aa94323f2a 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -109,6 +109,7 @@ CREATE TABLE IF NOT EXISTS `#__associations` ( `context` varchar(50) NOT NULL COMMENT 'The context of the associated item.', `key` char(32) NOT NULL COMMENT 'The key for the association computed from an md5 on associated ids.', `parent_id` int(11) NOT NULL DEFAULT -1 COMMENT 'The parent master item of an association.', + `assocParams` text, PRIMARY KEY (`context`,`id`), KEY `idx_key` (`key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index 158001cf0e238..477d54da71780 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -113,6 +113,7 @@ CREATE TABLE IF NOT EXISTS "#__associations" ( "context" varchar(50) NOT NULL, "key" char(32) NOT NULL, "parent_id" integer DEFAULT -1 NOT NULL, + "assocParams" text, CONSTRAINT "#__associations_idx_context_id" PRIMARY KEY ("context", "id") ); CREATE INDEX "#__associations_idx_key" ON "#__associations" ("key"); diff --git a/installation/src/Model/LanguagesModel.php b/installation/src/Model/LanguagesModel.php index bc8d3fb196731..548ae8fdda325 100644 --- a/installation/src/Model/LanguagesModel.php +++ b/installation/src/Model/LanguagesModel.php @@ -1423,7 +1423,7 @@ public function addAssociations($groupedAssociations) // If there is no master item in this association, then reset the parent_id to -1 // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; - $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($parentId)); + $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($parentId) . ',' . $db->quote('')); } $db->setQuery($query); diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index eb46a49f6d1f6..983342b786a8b 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -14,6 +14,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\Form\FormFactoryInterface; use Joomla\CMS\Language\Associations; +use Joomla\CMS\Language\LanguageHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Log\Log; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; @@ -22,10 +23,10 @@ use Joomla\CMS\Router\Route; use Joomla\CMS\Table\Table; use Joomla\CMS\UCM\UCMType; +use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; use Joomla\Registry\Registry; use Joomla\String\StringHelper; use Joomla\Utilities\ArrayHelper; -use Joomla\CMS\Language\LanguageHelper; /** * Prototype admin model. @@ -1319,6 +1320,12 @@ public function save($data) ); } + // Get association params before they get deleted + if($associations) + { + $associationsParams = MasterAssociationsHelper::getAssociationsParams($associations, $this->associationsContext); + } + // Get associationskey for edited item $db = $this->getDbo(); $query = $db->getQuery(true) @@ -1357,7 +1364,12 @@ public function save($data) { // If there is an association item with the globalMasterLanguage, then get his id $globalMasterLanguage = Associations::getGlobalMasterLanguage(); - $masterID = $associations[$globalMasterLanguage] ?? ''; + $masterId = $associations[$globalMasterLanguage] ?? ''; + // get id of the item that get saved + $dataId = (int) $table->id; + + // Get the modified date of master item + $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName()); // Adding new association for these items $key = md5(json_encode($associations)); @@ -1366,10 +1378,11 @@ public function save($data) foreach ($associations as $id) { - // If there is no master item in this association, then reset the parent_id to -1 - // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. - $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($parentId)); + $masterValues = MasterAssociationsHelper::getMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $old_key); + $parentId = $masterValues[0]; + $parentModified = $masterValues[1]; + + $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($parentId) . ',' . $db->quote($parentModified)); } $db->setQuery($query); diff --git a/plugins/sampledata/multilang/multilang.php b/plugins/sampledata/multilang/multilang.php index 1aa686c8a1c77..2b041bfca2e65 100644 --- a/plugins/sampledata/multilang/multilang.php +++ b/plugins/sampledata/multilang/multilang.php @@ -918,7 +918,7 @@ private function addAssociations($groupedAssociations) // If there is no master item in this association, then reset the parent_id to -1 // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; - $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($parentId)); + $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($parentId) . ',' . $db->quote('')); } $db->setQuery($query); diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index d41e7ee5583a9..e553640f5cad2 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -1035,8 +1035,9 @@ public function onExtensionAfterSave($context, $table, $isNew) /** * Method to set the master item of an association as parent and the children get the parent id + * Also reset the modified date of the master item. Master and children will be up-to-date, as they get the same modified date * - * @param string $language The global master language + * @param string $language The global master language * * @return void * @@ -1049,12 +1050,13 @@ private function _setMasterItem($language) // TODO add warning when master language changed - // if there is no global masterlanguage set, set all parent_ids to -1 + // if there is no global masterlanguage set, set all parent_ids to -1 and assocParams to null if (!$masterLanguage) { $resetQuery = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('parent_id') . ' = ' . -1); + ->set($db->quoteName('parent_id') . ' = ' . -1) + ->set($db->quoteName('assocParams') . ' = ' . $db->quote(null)); $db->setQuery($resetQuery); try @@ -1094,22 +1096,27 @@ private function _setMasterItem($language) { case 'com_content.item': $fromTable = $db->quoteName('#__content', 'e'); + $modified = $db->quoteName('e.modified'); break; case 'com_menus.item' : $fromTable = $db->quoteName('#__menu', 'e'); + $modified = ''; break; case 'com_categories.item': $fromTable = $db->quoteName('#__categories', 'e'); + $modified = $db->quoteName('e.modified_time'); break; case 'com_contact.item': $fromTable = $db->quoteName('#__contact_details', 'e'); + $modified = $db->quoteName('e.modified'); break; case 'com_newsfeeds.item': $fromTable = $db->quoteName('#__newsfeeds', 'e'); + $modified = $db->quoteName('e.modified'); break; } @@ -1127,10 +1134,23 @@ private function _setMasterItem($language) ->where($db->quoteName('key') . ' = ' . $db->quote($value)); $masterId = $db->setQuery($masterQuery)->loadResult(); + // Get master modified date + if($modified) + { + $masterModQuery = $db->getQuery(true) + ->select($modified) + ->from($fromTable) + ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); + $masterModified = $db->setQuery($masterModQuery)->loadResult(); + } + + $masterModified = $modified ? $masterModified : null; + // Set the master item as parent $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('parent_id') . ' = ' . 0) + ->set($db->quoteName('parent_id') . ' = ' . $db->quote(0)) + ->set($db->quoteName('assocParams') . ' = ' . $db->quote($masterModified)) ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)) ->where($db->quoteName('key') . ' = ' . $db->quote($value)); $db->setQuery($query); @@ -1150,6 +1170,7 @@ private function _setMasterItem($language) $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) ->set($db->quoteName('parent_id') . ' = ' . $db->quote($masterId)) + ->set($db->quoteName('assocParams') . ' = ' . $db->quote($masterModified)) ->where($db->quoteName('id') . ' <> ' . $db->quote($masterId)) ->where($db->quoteName('key') . ' = ' . $db->quote($value)); $db->setQuery($query); From 7da2da0497de38387ac321463970dea6c779a98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sat, 8 Jun 2019 20:34:39 +0200 Subject: [PATCH 13/98] display new association state 'outdated' in list views --- .../Field/ContentmasterlanguageField.php | 2 +- .../Helper/AssociationsHelper.php | 85 +++++++++---------- .../Helper/MasterAssociationsHelper.php | 68 ++++++++++++--- .../Service/HTML/AdministratorService.php | 85 ++++++++++++++++--- .../Service/HTML/AdministratorService.php | 75 ++++++++++++++-- .../Service/HTML/AdministratorService.php | 82 +++++++++++++++--- .../com_menus/Service/HTML/Menus.php | 10 ++- .../Service/HTML/AdministratorService.php | 66 ++++++++++++-- administrator/language/en-GB/en-GB.ini | 4 + libraries/src/Language/Associations.php | 3 +- 10 files changed, 387 insertions(+), 93 deletions(-) diff --git a/administrator/components/com_associations/Field/ContentmasterlanguageField.php b/administrator/components/com_associations/Field/ContentmasterlanguageField.php index d6cbf997e36e5..d970e5229f253 100644 --- a/administrator/components/com_associations/Field/ContentmasterlanguageField.php +++ b/administrator/components/com_associations/Field/ContentmasterlanguageField.php @@ -55,7 +55,7 @@ public function getOptions() if ($langCode->lang_code == $globalMasterLanguage) { $options[] = HTMLHelper::_('select.option', $langCode->lang_code, $langCode->title . ' - ' - . Text::_('COM_ASSOCIATIONS_MASTER_LANGUAGE') + . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE') ); } else diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index bec1cae7cd9c5..057c2eb820cfd 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -222,7 +222,15 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $globalMasterLanguage = Associations::getGlobalMasterLanguage(); // Get the associations list for this item. - $items = self::getAssociationList($extensionName, $typeName, $itemId); + $items = self::getAssociationList($extensionName, $typeName, $itemId); + $context = ($typeName === 'category') ? 'com_categories.item' : $extensionName . '.item'; + + // Get association params if there are associated items + if ($items) + { + $assocParams = MasterAssociationsHelper::getAssociationsParams($items, $context); + $masterId = $items[$globalMasterLanguage]['id'] ?? null; + } $titleFieldName = self::getTypeFieldName($extensionName, $typeName, 'title'); @@ -246,23 +254,12 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId { if ($globalMasterLanguage) { - // Get id of the master item - if ($itemLanguage === $globalMasterLanguage) - { - $masterId = $itemId; - } - else - { - // Don't display any other children to the child item - if (($langCode !== $globalMasterLanguage) && ($langCode !== $itemLanguage)) + // Don't display any other children to the child item + if (($langCode !== $globalMasterLanguage) && ($langCode !== $itemLanguage) && $itemLanguage !== $globalMasterLanguage) { unset($items[$langCode]); continue; } - - // Get id of the master item - $masterId = self::getGlobalMasterId($extensionName, $typeName, $itemId); - } } $title = $items[$langCode][$titleFieldName]; @@ -311,13 +308,15 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId if ($globalMasterLanguage) { + // Settings for the master language if ($globalMasterLanguage === $langCode) { $labelClass .= ' master-item'; - $languageTitle = $language->title . ' - ' . Text::_('COM_ASSOCIATIONS_MASTER_LANGUAGE'); + $languageTitle = $language->title . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); if ($globalMasterLanguage === $itemLanguage) { + // Do not define any child target as there can be more than one $target = ''; } else @@ -325,6 +324,32 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $target = $itemLanguage . ':' . $itemId . ':edit'; } } + // Setting for children + else + { + // When there is no associated master item, set it to target + if (!$masterId){ + $target = $globalMasterLanguage . ':0:add'; + } + + if (array_key_exists($items[$langCode]['id'], $assocParams) && array_key_exists($masterId, $assocParams)) + { + $associatedModifiedMaster = $assocParams[$items[$langCode]['id']]; + $lastModifiedMaster = $assocParams[$masterId]; + + if ($associatedModifiedMaster < $lastModifiedMaster) + { + $labelClass = 'badge-warning'; + $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC'); + $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; + $update = true; + } + else + { + $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); + } + } + } } } // Get html parameters for not associated items @@ -352,7 +377,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId if ($globalMasterLanguage === $langCode) { $labelClass .= ' master-item'; - $languageTitle = $language->title . ' - ' . Text::_('COM_ASSOCIATIONS_MASTER_LANGUAGE'); + $languageTitle = $language->title . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); $target = ''; } @@ -763,32 +788,4 @@ public static function getLanguagefilterPluginId() return $result; } - - /** - * Get the associated master item id from a child element. - * - * @param string $extensionName Extension Name - * @param string $typeName ItemType - * @param integer $itemId Item id - * - * @return integer $masterElementId The id of the associated master item - * - * @since 4.0 - */ - public static function getGlobalMasterId($extensionName, $typeName, $itemId) - { - $db = Factory::getDbo(); - - $context = ($typeName === 'category') ? 'com_categories.item' : $extensionName . '.item'; - - $parentQuery = $db->getQuery(true) - ->select($db->quoteName('parent_id')) - ->from($db->quoteName('#__associations')) - ->where($db->quoteName('id') . ' = ' . $db->quote($itemId)) - ->where($db->quoteName('context') . ' = ' . $db->quote($context)); - $masterId = $db->setQuery($parentQuery)->loadResult(); - - return (int) $masterId; - - } } diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 29d94e80659c5..8233f9ce69158 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -11,6 +11,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\Helper\ContentHelper; +use Joomla\CMS\Language\Text; defined('_JEXEC') or die; @@ -21,6 +22,37 @@ */ class MasterAssociationsHelper extends ContentHelper { + /** + * @param $globalMasterLanguage + * + * @return string + */ + public static function addNotAssociatedMasterLink($globalMasterLanguage) + { + $db = Factory::getDbo(); + $query = $db->getQuery(true) + ->select('title, sef') + ->from('#__languages') + ->where($db->quoteName('lang_code') . ' = ' + . $db->quote($globalMasterLanguage)); + $db->setQuery($query); + $globalMasterLanguageInfos = $db->loadAssoc(); + + $classes = 'hasPopover badge badge-secondary'; + $languageTitle = $globalMasterLanguageInfos['title'] . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); + $text = $globalMasterLanguageInfos['sef'] + ? strtoupper($globalMasterLanguageInfos['sef']) + : 'XX'; + $title = Text::_('JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC'); + $tooltip = htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); + $url = ''; + + $link = '' . $text . ''; + + return $link; + } /** * @param integer $itemId Item id @@ -66,9 +98,9 @@ public static function getMasterId($itemId, $context) /** * Method to get associated params of the master item. * - * @param array $associations the associations to be saved. + * @param array $associations the associations to be saved. * - * @param string $context the association context + * @param string $context the association context * * @return array associations with params * @@ -79,7 +111,8 @@ public static function getAssociationsParams($associations, $context) foreach ($associations as $langCode => $id) { - if(is_array($id)) { + if (is_array($id)) + { $id = $id['id']; } $query = $db->getQuery(true) @@ -88,7 +121,7 @@ public static function getAssociationsParams($associations, $context) ->where($db->quoteName('id') . ' = ' . $db->quote($id)) ->where($db->quoteName('context') . ' = ' . $db->quote($context)); $db->setQuery($query); - $param = $db->loadResult(); + $param = $db->loadResult(); $assocParams[$id] = $param; } @@ -96,16 +129,23 @@ public static function getAssociationsParams($associations, $context) } /** - * @param integer $id Item id - * @param integer $dataId Item id of an item that is going to be saved + * @param integer $id Item id + * @param integer $dataId Item id of an item that is going to be saved * @param integer $masterId - * @param string $masterModified th - * @param array $associationsParams modified date to associated items - * @param string $old_key the old association key + * @param string $masterModified th + * @param array $associationsParams modified date to associated items + * @param string $old_key the old association key * * @return array parent id and modified date */ - public static function getMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $old_key) { + public static function getMasterLanguageValues( + $id, + $dataId, + $masterId, + $masterModified, + $associationsParams, + $old_key + ) { if ($masterId) { @@ -131,20 +171,22 @@ public static function getMasterLanguageValues($id, $dataId, $masterId, $masterM else { // Set old modified date from master to existing associated child if not empty - $parentModified = empty($associationsParams[$id]) ? $masterModified : $associationsParams[$id]; + $parentModified = empty($associationsParams[$id]) + ? $masterModified : $associationsParams[$id]; } } else { // if modified date isn't set to the child item set it with current modified date from master - $parentModified = empty($associationsParams[$id]) ? $masterModified : $associationsParams[$id]; + $parentModified = empty($associationsParams[$id]) + ? $masterModified : $associationsParams[$id]; } } } // default values else { - $parentId = -1; + $parentId = -1; $parentModified = null; } diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index 8c0fe099d79e2..0e26846316e3a 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -14,8 +14,10 @@ use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Associations; +use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; +use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; use Joomla\Utilities\ArrayHelper; @@ -34,13 +36,13 @@ class AdministratorService * * @return string The language HTML * - * @since 3.2 * @throws \Exception + * @since 3.2 */ public function association($catid, $extension = 'com_content') { // Defaults - $html = ''; + $html = ''; $globalMasterLanguage = Associations::getGlobalMasterLanguage(); // Get the associations @@ -49,7 +51,7 @@ public function association($catid, $extension = 'com_content') $associations = ArrayHelper::toInteger($associations); // Get the associated categories - $db = Factory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true) ->select('c.id, c.title') ->select('l.sef as lang_sef') @@ -77,8 +79,21 @@ public function association($catid, $extension = 'com_content') throw new \Exception($e->getMessage(), 500, $e); } - // Check whether the current article is written in the global master language. - $masterElement = ($globalMasterLanguage && $items[$catid]->lang_code === $globalMasterLanguage) ? true : false; + if ($globalMasterLanguage) + { + // Check whether the current article is written in the global master language + $masterElement = (array_key_exists($catid, $items) + && ($items[$catid]->lang_code === $globalMasterLanguage)) + ? true + : false; + + // Check if there is a master item in the association and get his id if so + $masterId = array_key_exists($globalMasterLanguage, $associations) + ? $associations[$globalMasterLanguage] + : ''; + + $assocParams = MasterAssociationsHelper::getAssociationsParams($associations, 'com_categories.item'); + } if ($items) { @@ -91,16 +106,55 @@ public function association($catid, $extension = 'com_content') } // Don't display other children if the current item is a child of the master language. - if ($key !== $catid && $globalMasterLanguage !== $item->lang_code && !$masterElement && $globalMasterLanguage) + if (($key !== $catid) + && ($globalMasterLanguage !== $item->lang_code) + && !$masterElement + && $globalMasterLanguage) { unset($items[$key]); } - $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; - $url = Route::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); - $classes = 'hasPopover badge badge-success'; - $item->link = '' + $labelClass = 'badge-success'; + $languageTitle = $item->language_title; + $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; + $title = $item->title; + $url = Route::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id + . '&extension=' . $extension); + + if ($globalMasterLanguage) + { + if ($key === $masterId) + { + $labelClass .= ' master-item'; + $languageTitle = $item->language_title . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); + } + else + { + // get association state of child when a master exists + if ($masterId && array_key_exists($key, $assocParams) + && array_key_exists($masterId, $assocParams)) + { + $associatedModifiedMaster = $assocParams[$key]; + $lastModifiedMaster = $assocParams[$masterId]; + + if ($associatedModifiedMaster < $lastModifiedMaster) + { + $labelClass = 'badge-warning'; + $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') . '
'; + } + else + { + $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC') . '
'; + } + } + } + } + + $classes = 'hasPopover badge ' . $labelClass; + $tooltip = htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); + + $item->link = '
' . $text . ''; // Reorder the array, so the master item gets to the first place @@ -110,6 +164,15 @@ public function association($catid, $extension = 'com_content') unset($items[$key]); } } + + // If a master item doesn't exist, display that there is no association with the master language + if ($globalMasterLanguage && !$masterId) + { + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLanguage); + + // add this on the top of the array + $items = array('master' => array('link' => $link)) + $items; + } } HTMLHelper::_('bootstrap.popover'); diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index e626eae27e67c..60212a953210d 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -17,6 +17,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; +use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; use Joomla\Utilities\ArrayHelper; /** @@ -79,8 +80,21 @@ public function association($contactid) throw new \Exception($e->getMessage(), 500, $e); } - // Check whether the current article is written in the global master language. - $masterElement = ($globalMasterLanguage && $items[$contactid]->lang_code === $globalMasterLanguage) ? true : false; + if ($globalMasterLanguage) + { + // Check whether the current article is written in the global master language + $masterElement = (array_key_exists($contactid, $items) + && ($items[$contactid]->lang_code === $globalMasterLanguage)) + ? true + : false; + + // Check if there is a master item in the association and get his id if so + $masterId = array_key_exists($globalMasterLanguage, $associations) + ? $associations[$globalMasterLanguage] + : ''; + + $assocParams = MasterAssociationsHelper::getAssociationsParams($associations, 'com_contact.item'); + } if ($items) { @@ -98,12 +112,54 @@ public function association($contactid) unset($items[$key]); } + // Don't display other children if the current item is a child of the master language. + if (($key !== $contactid) + && ($globalMasterLanguage !== $item->lang_code) + && !$masterElement + && $globalMasterLanguage) + { + unset($items[$key]); + } + + $labelClass = 'badge-success'; + $languageTitle = $item->language_title; $text = strtoupper($item->lang_sef); + $title = $item->title; $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); - $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); - $classes = 'hasPopover badge badge-success'; - $item->link = '' . $text . ''; @@ -114,6 +170,15 @@ public function association($contactid) unset($items[$key]); } } + + // If a master item doesn't exist, display that there is no association with the master language + if ($globalMasterLanguage && !$masterId) + { + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLanguage); + + // add this on the top of the array + $items = array('master' => array('link' => $link)) + $items; + } } HTMLHelper::_('bootstrap.popover'); diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index e30a6d5fa0280..124f39da6acb7 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -17,6 +17,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; +use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; use Joomla\Utilities\ArrayHelper; /** @@ -39,7 +40,7 @@ class AdministratorService public function association($articleid) { // Defaults - $html = ''; + $html = ''; $globalMasterLanguage = Associations::getGlobalMasterLanguage(); // Get the associations @@ -51,7 +52,7 @@ public function association($articleid) } // Get the associated menu items - $db = Factory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true) ->select('c.*') ->select('l.sef as lang_sef') @@ -81,30 +82,80 @@ public function association($articleid) throw new \Exception($e->getMessage(), 500, $e); } - // Check whether the current article is written in the global master language. - $masterElement = ($globalMasterLanguage && $items[$articleid]->lang_code === $globalMasterLanguage) ? true : false; + if ($globalMasterLanguage) + { + // Check whether the current article is written in the global master language + $masterElement = (array_key_exists($articleid, $items) + && ($items[$articleid]->lang_code === $globalMasterLanguage)) + ? true + : false; + + // Check if there is a master item in the association and get his id if so + $masterId = array_key_exists($globalMasterLanguage, $associations) + ? $associations[$globalMasterLanguage] + : ''; + + $assocParams = MasterAssociationsHelper::getAssociationsParams($associations, 'com_content.item'); + } if ($items) { foreach ($items as $key => &$item) { // Don't continue for master, because it has been set here before - if ($key === 'master') { + if ($key === 'master') + { continue; } // Don't display other children if the current item is a child of the master language. - if (($key !== $articleid) && ($globalMasterLanguage !== $item->lang_code) && !$masterElement && $globalMasterLanguage) + if (($key !== $articleid) + && ($globalMasterLanguage !== $item->lang_code) + && !$masterElement + && $globalMasterLanguage) { unset($items[$key]); } - $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; - $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); - $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); - $classes = 'hasPopover badge badge-success'; + $labelClass = 'badge-success'; + $languageTitle = $item->language_title; + $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; + $title = $item->title; + $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); + + if ($globalMasterLanguage) + { + + if ($key === $masterId) + { + $labelClass .= ' master-item'; + $languageTitle = $item->language_title . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); + } + else + { + // get association state of child + if ($masterId && array_key_exists($key, $assocParams) && array_key_exists($masterId, $assocParams)) + { + $associatedModifiedMaster = $assocParams[$key]; + $lastModifiedMaster = $assocParams[$masterId]; + + if ($associatedModifiedMaster < $lastModifiedMaster) + { + $labelClass = 'badge-warning'; + $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') . '
'; + } + else + { + $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC') . '
'; + } + } + } + } + + $classes = 'hasPopover badge ' . $labelClass; + $tooltip = htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); - $item->link = '' . $text . ''; @@ -115,6 +166,15 @@ public function association($articleid) unset($items[$key]); } } + + // If a master item doesn't exist, display that there is no association with the master language + if ($globalMasterLanguage && !$masterId) + { + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLanguage); + + // add this on the top of the array + $items = array('master' => array('link' => $link)) + $items; + } } HTMLHelper::_('bootstrap.popover'); diff --git a/administrator/components/com_menus/Service/HTML/Menus.php b/administrator/components/com_menus/Service/HTML/Menus.php index 1821922ca6a37..00c8d7a3d50d4 100644 --- a/administrator/components/com_menus/Service/HTML/Menus.php +++ b/administrator/components/com_menus/Service/HTML/Menus.php @@ -79,8 +79,14 @@ public function association($itemid) throw new \Exception($e->getMessage(), 500); } - // Check whether the current article is written in the global master language. - $masterElement = ($globalMasterLanguage && $items[$itemid]->lang_code === $globalMasterLanguage) ? true : false; + if ($globalMasterLanguage) + { + // Check whether the current article is written in the global master language + $masterElement = (array_key_exists($itemid, $items) + && ($items[$itemid]->lang_code === $globalMasterLanguage)) + ? true + : false; + } // Construct html if ($items) diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index bdb2519264a2c..fc12fd407c1d9 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -17,6 +17,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; +use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; /** * Utility class for creating HTML Grids. @@ -78,8 +79,21 @@ public function association($newsfeedid) throw new \Exception($e->getMessage(), 500); } - // Check whether the current article is written in the global master language. - $masterElement = ($globalMasterLanguage && $items[$newsfeedid]->lang_code === $globalMasterLanguage) ? true : false; + if ($globalMasterLanguage) + { + // Check whether the current article is written in the global master language + $masterElement = (array_key_exists($newsfeedid, $items) + && ($items[$newsfeedid]->lang_code === $globalMasterLanguage)) + ? true + : false; + + // Check if there is a master item in the association and get his id if so + $masterId = array_key_exists($globalMasterLanguage, $associations) + ? $associations[$globalMasterLanguage] + : ''; + + $assocParams = MasterAssociationsHelper::getAssociationsParams($associations, 'com_newsfeeds.item'); + } if ($items) { @@ -97,12 +111,45 @@ public function association($newsfeedid) unset($items[$key]); } + $labelClass = 'badge-success'; + $languageTitle = $item->language_title; $text = strtoupper($item->lang_sef); + $title = $item->title; $url = Route::_('index.php?option=com_newsfeeds&task=newsfeed.edit&id=' . (int) $item->id); - $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); - $classes = 'hasPopover badge badge-success'; - $item->link = '' . $text . ''; @@ -113,6 +160,15 @@ public function association($newsfeedid) unset($items[$key]); } } + + // If a master item doesn't exist, display that there is no association with the master language + if ($globalMasterLanguage && !$masterId) + { + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLanguage); + + // add this on the top of the array + $items = array('master' => array('link' => $link)) + $items; + } } HTMLHelper::_('bootstrap.popover'); diff --git a/administrator/language/en-GB/en-GB.ini b/administrator/language/en-GB/en-GB.ini index d0da90c879ac7..37c6a80710340 100644 --- a/administrator/language/en-GB/en-GB.ini +++ b/administrator/language/en-GB/en-GB.ini @@ -279,6 +279,7 @@ JGLOBAL_ARTICLE_ORDER_DESC="The order that articles will show in." JGLOBAL_ARTICLE_ORDER_LABEL="Article Order" JGLOBAL_ARTICLES="Articles" JGLOBAL_ASSOC_NOT_POSSIBLE="To define associations, please make sure the item language is not set to 'All'." +JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE="Master" JGLOBAL_ASSOCIATIONS_NEW_ITEM_WARNING="To create associations, first save the item." JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON="Propagate" JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED="Failed propagating associations. You may have to select or create them manually." @@ -287,6 +288,9 @@ JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE="No associations exist to propagate. JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME="Associations have been set for: %s" JGLOBAL_ASSOCIATIONS_PROPAGATE_TIP="Propagates this item's existing associations." JGLOBAL_ASSOCIATIONS_RESET_WARNING="The language has been changed. If you save this item again it will reset the available associations. If this was not intended, close the item." +JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC="There is no association for the master language." +JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC="This item is outdated with the master item." +JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC="This item is up-to-date with the master item." JGLOBAL_AUTH_ACCESS_DENIED="Access Denied" JGLOBAL_AUTH_ACCESS_GRANTED="Access Granted" JGLOBAL_AUTH_BIND_FAILED="Failed binding to LDAP server" diff --git a/libraries/src/Language/Associations.php b/libraries/src/Language/Associations.php index 07de0d62a0ce2..c9c47ac0cd1a5 100644 --- a/libraries/src/Language/Associations.php +++ b/libraries/src/Language/Associations.php @@ -125,6 +125,7 @@ public static function getAssociations($extension, $tablename, $context, $id, $p if ($items) { + foreach ($items as $tag => $item) { if ($globalMasterLanguage) @@ -186,7 +187,7 @@ public static function isEnabled() /** * Method to get the global master language parameter for associations. * - * @return string empty if not set, lang_code otherwise + * @return string empty if not set, lang_code otherwise. * * @since 4.0 */ From 8c61dd61550c025dfc39a987350f6d10ad42d26a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sat, 8 Jun 2019 20:46:21 +0200 Subject: [PATCH 14/98] Add a filter for association states to the Associations View Adding this filter allows to quickly determine if a master element is associated or not and if child elements are either associated, not associated or obsolete. --- .../Model/AssociationsModel.php | 8 +++++--- .../View/Associations/HtmlView.php | 9 +++++++++ .../forms/filter_associations.xml | 17 ++++++++++++++--- .../layouts/joomla/searchtools/default.php | 16 +++++++++++++++- .../language/en-GB/en-GB.com_associations.ini | 5 ++++- .../atum/scss/blocks/_searchtools.scss | 8 ++++++++ 6 files changed, 55 insertions(+), 8 deletions(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 15d3132dec054..5c6a4bedcc4e1 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -47,6 +47,7 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu 'ordering', 'itemtype', 'language', + 'assocstate', 'association', 'menutype', 'menutype_title', @@ -83,8 +84,8 @@ protected function populateState($ordering = 'ordering', $direction = 'asc') // Set language select box to default site language or if set to the master language as default. $globalMasterLanguage = Associations::getGlobalMasterLanguage(); - $defaultLanguage = $globalMasterLanguage ?? ComponentHelper::getParams('com_languages')->get('site'); - $defaultItemType = 'com_content.article'; + $defaultLanguage = !empty($globalMasterLanguage) ? $globalMasterLanguage : ComponentHelper::getParams('com_languages')->get('site'); + $defaultItemType = 'com_content.article'; // Adjust the context to support modal layouts. if ($layout = $app->input->get('layout')) @@ -106,7 +107,7 @@ protected function populateState($ordering = 'ordering', $direction = 'asc') $this->setState('itemtype', $this->getUserStateFromRequest($this->context . '.itemtype', 'itemtype', $defaultItemType, 'string')); $this->setState('language', $this->getUserStateFromRequest($this->context . '.language', 'language', $defaultLanguage, 'string')); - + $this->setState('assocstate', $this->getUserStateFromRequest($this->context . '.assocstate', 'assocstate', '', 'string')); $this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string')); $this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'cmd')); $this->setState('filter.category_id', $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '', 'cmd')); @@ -148,6 +149,7 @@ protected function getStoreId($id = '') // Compile the store id. $id .= ':' . $this->getState('itemtype'); $id .= ':' . $this->getState('language'); + $id .= ':' . $this->getState('assocstate'); $id .= ':' . $this->getState('filter.search'); $id .= ':' . $this->getState('filter.state'); $id .= ':' . $this->getState('filter.category_id'); diff --git a/administrator/components/com_associations/View/Associations/HtmlView.php b/administrator/components/com_associations/View/Associations/HtmlView.php index c60f539f3a04c..5cac534f150c2 100644 --- a/administrator/components/com_associations/View/Associations/HtmlView.php +++ b/administrator/components/com_associations/View/Associations/HtmlView.php @@ -144,6 +144,15 @@ public function display($tpl = null) // This selectors doesn't have to activate the filter bar. unset($this->activeFilters['itemtype']); unset($this->activeFilters['language']); + unset($this->activeFilters['assocstate']); + + //Remove association state filter depending on global master language + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + + if(!$globalMasterLanguage){ + unset($this->activeFilters['assocstate']); + $this->filterForm->removeField('assocstate', 'filter'); + } // Remove filters options depending on selected type. if (empty($support['state'])) diff --git a/administrator/components/com_associations/forms/filter_associations.xml b/administrator/components/com_associations/forms/filter_associations.xml index 155a7a0abe78c..104ebfb8b270a 100644 --- a/administrator/components/com_associations/forms/filter_associations.xml +++ b/administrator/components/com_associations/forms/filter_associations.xml @@ -5,15 +5,26 @@ type="itemtype" filtermode="selector" onchange="this.form.submit()" - > - + /> + /> + + + + + + + diff --git a/administrator/components/com_associations/layouts/joomla/searchtools/default.php b/administrator/components/com_associations/layouts/joomla/searchtools/default.php index 51ccb2afe112a..2b8ddede867fd 100644 --- a/administrator/components/com_associations/layouts/joomla/searchtools/default.php +++ b/administrator/components/com_associations/layouts/joomla/searchtools/default.php @@ -11,6 +11,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Associations; /** @var array $displayData */ $data = $displayData; @@ -39,6 +40,8 @@ $data['options'] = array_merge($customOptions, $data['options']); +$globalMasterLanguage = Associations::getGlobalMasterLanguage(); + // Load search tools HTMLHelper::_('searchtools.form', $data['options']['formSelector'], $data['options']); @@ -47,6 +50,7 @@ + +
+
+
input; ?>
- + +
+
+ input; ?> +
+
+
sublayout('bar', $data); ?>
diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index 28e4fe2e54459..8a15ce2f07aff 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -19,6 +19,7 @@ COM_ASSOCIATIONS_EDIT_HIDE_REFERENCE="Hide Reference" COM_ASSOCIATIONS_EDIT_SHOW_REFERENCE="Show Reference" COM_ASSOCIATIONS_ERROR_NO_ASSOC="The Multilingual Associations component can't be used if the site is not set as multilingual and/or Associations is not enabled in the Language Filter plugin." COM_ASSOCIATIONS_ERROR_NO_TYPE="The item type selected does not exist for this component." +COM_ASSOCIATIONS_FILTER_ASSOCIATION_STATE="All Association States" COM_ASSOCIATIONS_FILTER_SEARCH_DESC="Search an item by its title" COM_ASSOCIATIONS_FILTER_SEARCH_LABEL="Search item" COM_ASSOCIATIONS_FILTER_SELECT_ITEM_TYPE="- Select Item Type -" @@ -27,7 +28,6 @@ COM_ASSOCIATIONS_HEADING_MENUTYPE="Menu" COM_ASSOCIATIONS_HEADING_MENUTYPE_ASC="Menu ascending" COM_ASSOCIATIONS_HEADING_MENUTYPE_DESC="Menu descending" COM_ASSOCIATIONS_ITEMS="Items" -COM_ASSOCIATIONS_MASTER_LANGUAGE="Master" COM_ASSOCIATIONS_NO_ASSOCIATION="There is no association for this language" COM_ASSOCIATIONS_NOTICE_NO_SELECTORS="Please select an Item Type and a reference language to view the associations." COM_ASSOCIATIONS_PURGE="Delete All Associations" @@ -41,6 +41,9 @@ COM_ASSOCIATIONS_SAVE_TARGET="Save Target" COM_ASSOCIATIONS_SELECT_MENU="- Select Menu -" COM_ASSOCIATIONS_SELECT_TARGET="Select Target" COM_ASSOCIATIONS_SELECT_TARGET_LANGUAGE="- Select Target Language -" +COM_ASSOCIATIONS_STATE_NOT_ASSOCIATED="Not Associated" +COM_ASSOCIATIONS_STATE_OUTDATED="Outdated" +COM_ASSOCIATIONS_STATE_UP_TO_DATE="Up-to-date" COM_ASSOCIATIONS_TABLE_CAPTION="Table of Associations" COM_ASSOCIATIONS_TITLE="Associations" COM_ASSOCIATIONS_TITLE_EDIT="Multilingual Associations: Edit Associations (%1s > %2s)" diff --git a/administrator/templates/atum/scss/blocks/_searchtools.scss b/administrator/templates/atum/scss/blocks/_searchtools.scss index ac6a3a9b5b376..2ca1dd6b1e2b4 100644 --- a/administrator/templates/atum/scss/blocks/_searchtools.scss +++ b/administrator/templates/atum/scss/blocks/_searchtools.scss @@ -60,6 +60,14 @@ margin-right: auto; } + .js-stools-container-selector-second { + margin-right: 8px; + + html[dir=rtl] & { + margin-left: 8px; + } + } + .js-stools-container-bar { .btn-toolbar { From e6d7e3c9d2a42d4d97dd54947cdff8a38b4485d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sat, 8 Jun 2019 20:53:01 +0200 Subject: [PATCH 15/98] Add sql for filter for association states to the Associations View --- .../Model/AssociationsModel.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 5c6a4bedcc4e1..f84ab66ea8211 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -445,6 +445,50 @@ protected function getListQuery() } } + // Filter on association state + $assocStateField = $this->state->get('assocstate'); + + if ($assocStateField !== '') + { + // not associated + if ($assocStateField === '-1') + { + $subQuery = $db->getQuery(true) + ->select('COUNT(*)') + ->from('#__languages'); + $db->setQuery($subQuery); + $countLanguages = $db->loadResult(); + + // join over associations where id does not exists or where child does not exists + $query->where('((' . $db->quoteName('asso.id') . ' IS NULL )' + // if we are on the childlanguage + . ' OR ( ' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') + . ' AND ' . $db->quoteName('asso2.id') . ' < ' . $db->quote($countLanguages) . ' ))'); + } + + // outdated + if ($assocStateField === '0') + { + echo "
" . print_r("outdated") . "
"; + // if we are on the masterlanguage + $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') + . ' AND ' . $db->quoteName('asso2.assocParams') . ' < ' . $db->quoteName('asso.assocParams') . ')' + // if we are on the childlanguage + . ' OR (' . $db->quoteName('asso.assocParams') . ' < ' . $db->quoteName('asso2.assocParams') + . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.parent_id') . '))'); + } + + // up-to-date + if ($assocStateField === '1') + { + $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') + . ' AND ' . $db->quoteName('asso2.assocParams') . ' = ' . $db->quoteName('asso.assocParams') . ')' + // if we are on the childlanguage + . ' OR (' . $db->quoteName('asso.assocParams') . ' = ' . $db->quoteName('asso2.assocParams') + . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.parent_id') . '))'); + } + } + // Add the group by clause $query->group($db->quoteName($groupby)); From e0ceadd912eab9cd1f58459dc900be6af9229d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sun, 9 Jun 2019 00:00:35 +0200 Subject: [PATCH 16/98] Fix Bug when changing global master language Set parent id correctly if no master item is present. --- .../system/languagefilter/languagefilter.php | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index e553640f5cad2..5e88aa23c26c2 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -95,7 +95,7 @@ class PlgSystemLanguageFilter extends CMSPlugin * Constructor. * * @param object &$subject The object to observe - * @param array $config An optional associative array of configuration settings. + * @param array $config An optional associative array of configuration settings. * * @since 1.6 */ @@ -968,9 +968,9 @@ private function getLanguageCookie() * Method is called when an extension is going to be saved * change parameters for master language because there depends on other parameters * - * @param string $context The extension - * @param JTable $table DataBase Table object - * @param boolean $isNew If the extension is new or not + * @param string $context The extension + * @param JTable $table DataBase Table object + * @param boolean $isNew If the extension is new or not * * @return void * @@ -978,10 +978,10 @@ private function getLanguageCookie() */ public function onExtensionBeforeSave($context, $table, $isNew) { - // get the params to save - $params = json_decode($table->params); - $tableElement = $table->element; - $pluginStatus = $table->enabled; + // Get the params to save + $params = json_decode($table->params); + $tableElement = $table->element; + $pluginStatus = $table->enabled; $itemAssocStatus = $params->item_associations; if ($context != 'com_plugins.plugin' && $tableElement != 'languagefilter') @@ -989,18 +989,18 @@ public function onExtensionBeforeSave($context, $table, $isNew) return true; } - // if the plugin and the parameter item associations are enabled then set the correct value for the global master language - if($pluginStatus && $itemAssocStatus) + // If the plugin and the parameter item associations are enabled then set the correct value for the global master language + if ($pluginStatus && $itemAssocStatus) { - $globalMasterLanguage = ($params->use_master_language === '1') + $globalMasterLanguage = ($params->use_master_language === '1') ? $params->global_master_language : ''; $params->global_master_language = $globalMasterLanguage; } - // reset parameters for master language + // Reset parameters for master language else { - $params->use_master_language = ''; + $params->use_master_language = ''; $params->global_master_language = ''; } @@ -1011,9 +1011,9 @@ public function onExtensionBeforeSave($context, $table, $isNew) * After save extensions * Method is called when an extension has been saved * - * @param string $context The extension - * @param JTable $table DataBase Table object - * @param boolean $isNew If the extension is new or not + * @param string $context The extension + * @param JTable $table DataBase Table object + * @param boolean $isNew If the extension is new or not * * @return void * @@ -1037,7 +1037,7 @@ public function onExtensionAfterSave($context, $table, $isNew) * Method to set the master item of an association as parent and the children get the parent id * Also reset the modified date of the master item. Master and children will be up-to-date, as they get the same modified date * - * @param string $language The global master language + * @param string $language The global master language * * @return void * @@ -1096,27 +1096,27 @@ private function _setMasterItem($language) { case 'com_content.item': $fromTable = $db->quoteName('#__content', 'e'); - $modified = $db->quoteName('e.modified'); + $modified = $db->quoteName('e.modified'); break; case 'com_menus.item' : $fromTable = $db->quoteName('#__menu', 'e'); - $modified = ''; + $modified = ''; break; case 'com_categories.item': $fromTable = $db->quoteName('#__categories', 'e'); - $modified = $db->quoteName('e.modified_time'); + $modified = $db->quoteName('e.modified_time'); break; case 'com_contact.item': $fromTable = $db->quoteName('#__contact_details', 'e'); - $modified = $db->quoteName('e.modified'); + $modified = $db->quoteName('e.modified'); break; case 'com_newsfeeds.item': $fromTable = $db->quoteName('#__newsfeeds', 'e'); - $modified = $db->quoteName('e.modified'); + $modified = $db->quoteName('e.modified'); break; } @@ -1135,24 +1135,26 @@ private function _setMasterItem($language) $masterId = $db->setQuery($masterQuery)->loadResult(); // Get master modified date - if($modified) + if ($modified) { $masterModQuery = $db->getQuery(true) ->select($modified) ->from($fromTable) ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); - $masterModified = $db->setQuery($masterModQuery)->loadResult(); + $masterModified = $db->setQuery($masterModQuery)->loadResult(); } $masterModified = $modified ? $masterModified : null; + $masterId = $masterId ?? -1; - // Set the master item as parent + // Set the master item as parent and set his modified date $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) ->set($db->quoteName('parent_id') . ' = ' . $db->quote(0)) ->set($db->quoteName('assocParams') . ' = ' . $db->quote($masterModified)) ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)) - ->where($db->quoteName('key') . ' = ' . $db->quote($value)); + ->where($db->quoteName('key') . ' = ' . $db->quote($value)) + ->where($db->quoteName('context') . ' = ' . $db->quote($assocContext)); $db->setQuery($query); try @@ -1172,7 +1174,8 @@ private function _setMasterItem($language) ->set($db->quoteName('parent_id') . ' = ' . $db->quote($masterId)) ->set($db->quoteName('assocParams') . ' = ' . $db->quote($masterModified)) ->where($db->quoteName('id') . ' <> ' . $db->quote($masterId)) - ->where($db->quoteName('key') . ' = ' . $db->quote($value)); + ->where($db->quoteName('key') . ' = ' . $db->quote($value)) + ->where($db->quoteName('context') . ' = ' . $db->quote($assocContext)); $db->setQuery($query); try From 0eed838174ae57ed4760a05cf92d768a5a3177fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sun, 9 Jun 2019 00:04:14 +0200 Subject: [PATCH 17/98] Fix bug where newsfeeds and contacts get the same assoc key To prevent associations from receiving the same association key, since id and language can be the same in different contexts, the context is also added as differentiation. --- libraries/src/MVC/Model/AdminModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 983342b786a8b..2f8f6abff65b9 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -1372,7 +1372,7 @@ public function save($data) $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName()); // Adding new association for these items - $key = md5(json_encode($associations)); + $key = md5(json_encode($associations) . $context); $query = $db->getQuery(true) ->insert('#__associations'); From 211400d39a564970da5d1e63aca49202558e0a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sun, 9 Jun 2019 00:06:55 +0200 Subject: [PATCH 18/98] Fix Bug for displaying associations without master language --- .../Service/HTML/AdministratorService.php | 30 ++++++++-------- .../Service/HTML/AdministratorService.php | 35 ++++++++---------- .../Service/HTML/AdministratorService.php | 29 ++++++++------- .../com_menus/Service/HTML/Menus.php | 36 ++++++++++++++----- .../Service/HTML/AdministratorService.php | 25 ++++++------- 5 files changed, 84 insertions(+), 71 deletions(-) diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index 0e26846316e3a..9f8898bf3c81e 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -99,21 +99,6 @@ public function association($catid, $extension = 'com_content') { foreach ($items as $key => &$item) { - // Don't continue for master, because it has been set here before - if ($key === 'master') - { - continue; - } - - // Don't display other children if the current item is a child of the master language. - if (($key !== $catid) - && ($globalMasterLanguage !== $item->lang_code) - && !$masterElement - && $globalMasterLanguage) - { - unset($items[$key]); - } - $labelClass = 'badge-success'; $languageTitle = $item->language_title; $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; @@ -123,6 +108,21 @@ public function association($catid, $extension = 'com_content') if ($globalMasterLanguage) { + + // Don't continue for master, because it has been set here before + if ($key === 'master') + { + continue; + } + + // Don't display other children if the current item is a child of the master language. + if (($key !== $catid) + && ($globalMasterLanguage !== $item->lang_code) + && !$masterElement) + { + unset($items[$key]); + } + if ($key === $masterId) { $labelClass .= ' master-item'; diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index 60212a953210d..75640bd8453c6 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -100,27 +100,6 @@ public function association($contactid) { foreach ($items as $key => &$item) { - // Don't continue for master, because it has been set here before - if ($key === 'master') - { - continue; - } - - // Don't display other children if the current item is a child of the master language. - if ($key !== $contactid && $globalMasterLanguage !== $item->lang_code && !$masterElement && $globalMasterLanguage) - { - unset($items[$key]); - } - - // Don't display other children if the current item is a child of the master language. - if (($key !== $contactid) - && ($globalMasterLanguage !== $item->lang_code) - && !$masterElement - && $globalMasterLanguage) - { - unset($items[$key]); - } - $labelClass = 'badge-success'; $languageTitle = $item->language_title; $text = strtoupper($item->lang_sef); @@ -130,6 +109,20 @@ public function association($contactid) if ($globalMasterLanguage) { + // Don't continue for master, because it has been set here before + if ($key === 'master') + { + continue; + } + + // Don't display other children if the current item is a child of the master language. + if (($key !== $contactid) + && ($globalMasterLanguage !== $item->lang_code) + && !$masterElement) + { + unset($items[$key]); + } + if ($key === $masterId) { $labelClass .= ' master-item'; diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index 124f39da6acb7..bdc2717e6237e 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -102,21 +102,6 @@ public function association($articleid) { foreach ($items as $key => &$item) { - // Don't continue for master, because it has been set here before - if ($key === 'master') - { - continue; - } - - // Don't display other children if the current item is a child of the master language. - if (($key !== $articleid) - && ($globalMasterLanguage !== $item->lang_code) - && !$masterElement - && $globalMasterLanguage) - { - unset($items[$key]); - } - $labelClass = 'badge-success'; $languageTitle = $item->language_title; $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; @@ -126,6 +111,20 @@ public function association($articleid) if ($globalMasterLanguage) { + // Don't continue for master, because it has been set here before + if ($key === 'master') + { + continue; + } + + // Don't display other children if the current item is a child of the master language. + if (($key !== $articleid) + && ($globalMasterLanguage !== $item->lang_code) + && !$masterElement) + { + unset($items[$key]); + } + if ($key === $masterId) { $labelClass .= ' master-item'; diff --git a/administrator/components/com_menus/Service/HTML/Menus.php b/administrator/components/com_menus/Service/HTML/Menus.php index 00c8d7a3d50d4..fd68eda4d8f9b 100644 --- a/administrator/components/com_menus/Service/HTML/Menus.php +++ b/administrator/components/com_menus/Service/HTML/Menus.php @@ -17,6 +17,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; +use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; use Joomla\Component\Menus\Administrator\Helper\MenusHelper; use Joomla\Registry\Registry; @@ -86,6 +87,11 @@ public function association($itemid) && ($items[$itemid]->lang_code === $globalMasterLanguage)) ? true : false; + + // Check if there is a master item in the association and get his id if so + $masterId = array_key_exists($globalMasterLanguage, $associations) + ? $associations[$globalMasterLanguage] + : ''; } // Construct html @@ -93,16 +99,21 @@ public function association($itemid) { foreach ($items as $key => &$item) { - // Don't continue for master, because it has been set here before - if ($key === 'master') + if ($globalMasterLanguage) { - continue; - } + // Don't continue for master, because it has been set here before + if ($key === 'master') + { + continue; + } - // Don't display other children if the current item is a child of the master language. - if ($key !== $itemid && $globalMasterLanguage !== $item->lang_code && !$masterElement && $globalMasterLanguage) - { - unset($items[$key]); + // Don't display other children if the current item is a child of the master language. + if ($key !== $itemid + && $globalMasterLanguage !== $item->lang_code + && !$masterElement) + { + unset($items[$key]); + } } $text = strtoupper($item->lang_sef); @@ -121,6 +132,15 @@ public function association($itemid) unset($items[$key]); } } + + // If a master item doesn't exist, display that there is no association with the master language + if ($globalMasterLanguage && !$masterId) + { + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLanguage); + + // add this on the top of the array + $items = array('master' => array('link' => $link)) + $items; + } } HTMLHelper::_('bootstrap.popover'); diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index fc12fd407c1d9..d7eff729e5f64 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -99,18 +99,6 @@ public function association($newsfeedid) { foreach ($items as $key => &$item) { - // Don't continue for master, because it has been set here before - if ($key === 'master') - { - continue; - } - - // Don't display other children if the current item is a child of the master language. - if ($key !== $newsfeedid && $globalMasterLanguage !== $item->lang_code && !$masterElement && $globalMasterLanguage) - { - unset($items[$key]); - } - $labelClass = 'badge-success'; $languageTitle = $item->language_title; $text = strtoupper($item->lang_sef); @@ -119,6 +107,19 @@ public function association($newsfeedid) if ($globalMasterLanguage) { + // Don't continue for master, because it has been set here before + if ($key === 'master') + { + continue; + } + + // Don't display other children if the current item is a child of the master language. + if ($key !== $newsfeedid + && ($globalMasterLanguage !== $item->lang_code) + && !$masterElement) + { + unset($items[$key]); + } if ($key === $masterId) { From 75ccfe911eb636feb293ccc9977d85c408fb970c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 10 Jun 2019 16:01:26 +0200 Subject: [PATCH 19/98] Adding labels to select for accessibility reasons As described in WCAG 3.3.2: 'Labels or instructions are provided when content requires user input. (Level A)' --- .../Field/ContentmasterlanguageField.php | 2 ++ .../com_associations/forms/filter_associations.xml | 9 +++++++-- .../layouts/joomla/searchtools/default.php | 10 ++++++++++ .../language/en-GB/en-GB.com_associations.ini | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_associations/Field/ContentmasterlanguageField.php b/administrator/components/com_associations/Field/ContentmasterlanguageField.php index d970e5229f253..dfa7065ab9812 100644 --- a/administrator/components/com_associations/Field/ContentmasterlanguageField.php +++ b/administrator/components/com_associations/Field/ContentmasterlanguageField.php @@ -49,6 +49,8 @@ public function getOptions() $contentLanguages = LanguageHelper::getContentLanguages(array(0, 1)); $options = array(); + $options[] = HTMLHelper::_('select.option', '', Text::_('JOPTION_SELECT_LANGUAGE'), array('disable'=>'true')); + foreach ($contentLanguages as $langCode) { // Add information to the language if it is the global master language diff --git a/administrator/components/com_associations/forms/filter_associations.xml b/administrator/components/com_associations/forms/filter_associations.xml index 104ebfb8b270a..b9c5c103c5e97 100644 --- a/administrator/components/com_associations/forms/filter_associations.xml +++ b/administrator/components/com_associations/forms/filter_associations.xml @@ -3,13 +3,17 @@ + > + + @@ -17,14 +21,15 @@ + - diff --git a/administrator/components/com_associations/layouts/joomla/searchtools/default.php b/administrator/components/com_associations/layouts/joomla/searchtools/default.php index 2b8ddede867fd..636f9bb4ec01d 100644 --- a/administrator/components/com_associations/layouts/joomla/searchtools/default.php +++ b/administrator/components/com_associations/layouts/joomla/searchtools/default.php @@ -12,6 +12,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Associations; +use Joomla\CMS\Language\Text; /** @var array $displayData */ $data = $displayData; @@ -55,6 +56,9 @@
+ input; ?>
@@ -64,12 +68,18 @@
+ input; ?>
+ input; ?>
diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index 8a15ce2f07aff..5791f7b2f57a5 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -22,6 +22,7 @@ COM_ASSOCIATIONS_ERROR_NO_TYPE="The item type selected does not exist for this c COM_ASSOCIATIONS_FILTER_ASSOCIATION_STATE="All Association States" COM_ASSOCIATIONS_FILTER_SEARCH_DESC="Search an item by its title" COM_ASSOCIATIONS_FILTER_SEARCH_LABEL="Search item" +COM_ASSOCIATIONS_FILTER_SELECT_ASSOCIATION_STATE="- Select Association State -" COM_ASSOCIATIONS_FILTER_SELECT_ITEM_TYPE="- Select Item Type -" COM_ASSOCIATIONS_HEADING_ASSOCIATION="Associations" COM_ASSOCIATIONS_HEADING_MENUTYPE="Menu" From b9361e6b529b2f40513c7382ff36ae5975f346aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 10 Jun 2019 17:10:04 +0200 Subject: [PATCH 20/98] change fields order and add description to these fields Remove the fieldset for the master language and position its fields after the item association field, as the master fields depend on it. --- .../en-GB/en-GB.plg_system_languagefilter.ini | 8 ++-- .../system/languagefilter/languagefilter.xml | 46 +++++++++---------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini index e9b6cfef81c8b..b234bdfe9ce0a 100644 --- a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini +++ b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini @@ -9,13 +9,13 @@ PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_LABEL="Add Alternate Meta Tags" PLG_SYSTEM_LANGUAGEFILTER_FIELD_AUTOMATIC_CHANGE_LABEL="Automatic Language Change" PLG_SYSTEM_LANGUAGEFILTER_FIELD_COOKIE_LABEL="Cookie Lifetime" PLG_SYSTEM_LANGUAGEFILTER_FIELD_DETECT_BROWSER_LABEL="Language Selection for new Visitors" +PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_LABEL="Global Master Language" +PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_DESC="Note that changing this value will overwrite all existing Master Child relationships with their states." PLG_SYSTEM_LANGUAGEFILTER_FIELD_ITEM_ASSOCIATIONS_LABEL="Item Associations" +PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_LABEL="Set a Master Language?" +PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_DESC="When enabled, a master-child relationship is added between the languages, depending on the selected master language. This adds an additional 'outdated' state to a child element depending on its master. If disabled, functions dependent on this data are not available." PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LABEL="Add x-default Meta Tag" PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LANGUAGE_LABEL="x-default Language" -PLG_SYSTEM_LANGUAGEFILTER_MASTER_LANGUAGE_DESC="These settings apply for all multilingual associations. By setting an master language, the association states 'not associated', 'new', 'outdated', 'up-to-date' are set for translated items, depending on changes to items in the master language." -PLG_SYSTEM_LANGUAGEFILTER_MASTER_LANGUAGE_FIELD_GLOBAL_MASTER_LANGUAGE_LABEL="Global Master Language" -PLG_SYSTEM_LANGUAGEFILTER_MASTER_LANGUAGE_FIELD_USE_MASTER_LANGUAGE_LABEL="Set a Master Language?" -PLG_SYSTEM_LANGUAGEFILTER_MASTER_LANGUAGE_LABEL="Master Language" PLG_SYSTEM_LANGUAGEFILTER_OPTION_DEFAULT_LANGUAGE="Default frontend language" PLG_SYSTEM_LANGUAGEFILTER_FIELD_REMOVE_DEFAULT_PREFIX_LABEL="Remove URL Language Code" PLG_SYSTEM_LANGUAGEFILTER_OPTION_SESSION="Session" diff --git a/plugins/system/languagefilter/languagefilter.xml b/plugins/system/languagefilter/languagefilter.xml index d89fd521db9de..6b0bc8970fa2a 100644 --- a/plugins/system/languagefilter/languagefilter.xml +++ b/plugins/system/languagefilter/languagefilter.xml @@ -56,6 +56,28 @@
+ + + + + + + PLG_SYSTEM_LANGUAGEFILTER_OPTION_SESSION -
- - - - - -
From b9d451ca0bc0ab7d2500873e64e1213d6571d2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 11 Jun 2019 16:02:06 +0200 Subject: [PATCH 21/98] fix filter by association state Filtering for "not associated" did not work correctly when either a child of a master item is not associated or when there is no master item for a child. --- .../Model/AssociationsModel.php | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index f84ab66ea8211..2c724b3e27768 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -445,7 +445,7 @@ protected function getListQuery() } } - // Filter on association state + // Filter by association state $assocStateField = $this->state->get('assocstate'); if ($assocStateField !== '') @@ -453,27 +453,36 @@ protected function getListQuery() // not associated if ($assocStateField === '-1') { - $subQuery = $db->getQuery(true) + $languageQuery = $db->getQuery(true) ->select('COUNT(*)') - ->from('#__languages'); - $db->setQuery($subQuery); + ->from($db->quoteName('#__languages')); + $db->setQuery($languageQuery); $countLanguages = $db->loadResult(); - // join over associations where id does not exists or where child does not exists + // get all keys where not all languages are associated + $assocQuery = $db->getQuery(true) + ->select($db->quoteName('key')) + ->from($db->quoteName('#__associations')) + ->group($db->quoteName('key')) + ->having('COUNT(*) < ' . $countLanguages); + + // join over associations where id does not exists $query->where('((' . $db->quoteName('asso.id') . ' IS NULL )' - // if we are on the childlanguage - . ' OR ( ' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') - . ' AND ' . $db->quoteName('asso2.id') . ' < ' . $db->quote($countLanguages) . ' ))'); + // or if we are on the childlanguage and there is no master language + . ' OR ( ' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quote('-1') . ')' + // or a child of the master does not exist + . ' OR ( ' . $db->quoteName('asso.key') . ' IN (' . $assocQuery . ') + AND ' . $db->quoteName('asso.parent_id') . ' = ' . $db->quote('0') . ')' + . ')'); } // outdated if ($assocStateField === '0') { - echo "
" . print_r("outdated") . "
"; - // if we are on the masterlanguage + // if we are on the masterlanguage and we check the state of the children $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') . ' AND ' . $db->quoteName('asso2.assocParams') . ' < ' . $db->quoteName('asso.assocParams') . ')' - // if we are on the childlanguage + // if we are on the childlanguage we check its state comparing to its master . ' OR (' . $db->quoteName('asso.assocParams') . ' < ' . $db->quoteName('asso2.assocParams') . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.parent_id') . '))'); } @@ -481,9 +490,10 @@ protected function getListQuery() // up-to-date if ($assocStateField === '1') { + // if we are on the masterlanguage and we check the state of the children $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') . ' AND ' . $db->quoteName('asso2.assocParams') . ' = ' . $db->quoteName('asso.assocParams') . ')' - // if we are on the childlanguage + // if we are on the childlanguage we check its state comparing to its master . ' OR (' . $db->quoteName('asso.assocParams') . ' = ' . $db->quoteName('asso2.assocParams') . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.parent_id') . '))'); } From 69b7c054d177eb087deb6540ac877877dd79fe80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sun, 16 Jun 2019 13:27:53 +0200 Subject: [PATCH 22/98] fix filter with correct context for categories in the associations table --- .../components/com_associations/Model/AssociationsModel.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 2c724b3e27768..8420d57c19a79 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -175,6 +175,7 @@ protected function getListQuery() $extension = AssociationsHelper::getSupportedExtension($extensionName); $types = $extension->get('types'); + $assocContextName = ($typeName ==='category') ? 'com_categories.item' : $extensionName . '.item'; if (array_key_exists($typeName, $types)) { @@ -249,7 +250,7 @@ protected function getListQuery() ->join( 'LEFT', $db->quoteName('#__associations', 'asso') . ' ON ' . $db->quoteName('asso.id') . ' = ' . $db->quoteName($fields['id']) - . ' AND ' . $db->quoteName('asso.context') . ' = ' . $db->quote($extensionName . '.item') + . ' AND ' . $db->quoteName('asso.context') . ' = ' . $db->quote($assocContextName) ) ->join('LEFT', $db->quoteName('#__associations', 'asso2') . ' ON ' . $db->quoteName('asso2.key') . ' = ' . $db->quoteName('asso.key')); From 7171c110d1660d8fe56cf6bb72e00581ed65e605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sun, 16 Jun 2019 13:31:55 +0200 Subject: [PATCH 23/98] add modified date when installing multilingual sample data --- plugins/sampledata/multilang/multilang.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/sampledata/multilang/multilang.php b/plugins/sampledata/multilang/multilang.php index 5266318083bcd..115a74f3f1c03 100644 --- a/plugins/sampledata/multilang/multilang.php +++ b/plugins/sampledata/multilang/multilang.php @@ -907,7 +907,9 @@ private function addAssociations($groupedAssociations) foreach ($groupedAssociations as $context => $associations) { // If there is an association item with the globalMasterLanguage, then get his id - $masterID = $associations[$globalMasterLanguage] ?? ''; + $masterId = $associations[$globalMasterLanguage] ?? ''; + // TODO when there is a way to get the history save date from here, use it. + $masterModified = ($context === 'com_menus.item' || !$globalMasterLanguage) ? null : '0000-00-00 00:00:00'; $key = md5(json_encode($associations)); $query = $db->getQuery(true) ->insert('#__associations'); @@ -916,8 +918,8 @@ private function addAssociations($groupedAssociations) { // If there is no master item in this association, then reset the parent_id to -1 // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. - $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; - $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($parentId) . ',' . $db->quote('')); + $parentId = $masterId ? ($masterId === $id ? 0 : $masterId) : -1; + $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($parentId) . ',' . $db->quote($masterModified)); } $db->setQuery($query); From a123b14685ec7ec7802e018fa02879b98da3123e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sun, 16 Jun 2019 16:21:42 +0200 Subject: [PATCH 24/98] use date of history if enabled instead of modified date for master item - If Version is enabled then store the save_date of the ucm_history table into assocParams. This update the table just in cases when there were changes made when saving an item. - simplify the conditions in getMasterLanguageValues(). - when the languagefilter plugin get saved it doesn't reset the master id and his modified date when the global master language doesn't changed. - add a horizontal before item_associations and after global master language within the languagefilter plugin --- .../Helper/MasterAssociationsHelper.php | 109 +++++++++--------- .../com_categories/Model/CategoryModel.php | 4 +- libraries/src/MVC/Model/AdminModel.php | 7 +- .../system/languagefilter/languagefilter.php | 63 ++++++++-- .../system/languagefilter/languagefilter.xml | 10 ++ 5 files changed, 122 insertions(+), 71 deletions(-) diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 8233f9ce69158..530bce3191f3e 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -9,9 +9,12 @@ namespace Joomla\Component\Associations\Administrator\Helper; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Helper\ContentHelper; +use Joomla\CMS\Helper\ContentHistoryHelper; use Joomla\CMS\Language\Text; +use Joomla\CMS\Table\Table; defined('_JEXEC') or die; @@ -129,23 +132,16 @@ public static function getAssociationsParams($associations, $context) } /** - * @param integer $id Item id - * @param integer $dataId Item id of an item that is going to be saved - * @param integer $masterId - * @param string $masterModified th - * @param array $associationsParams modified date to associated items - * @param string $old_key the old association key + * @param integer $id Item id + * @param integer $dataId Item id of an item that is going to be saved + * @param integer $masterId Id of the associated master item + * @param string $masterModified the latest modified date of the master + * @param array $associationsParams modified date to associated items + * @param string $old_key the old association key * * @return array parent id and modified date */ - public static function getMasterLanguageValues( - $id, - $dataId, - $masterId, - $masterModified, - $associationsParams, - $old_key - ) { + public static function getMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $old_key) { if ($masterId) { @@ -161,29 +157,19 @@ public static function getMasterLanguageValues( { $parentId = $masterId; - if (!$old_key) + // if modified date isn't set to the child item set it with current modified date from master + $parentModified = empty($associationsParams[$id]) + ? $masterModified + : $associationsParams[$id]; + + if (!$old_key && ($dataId === $id)) { // Add modified date from master to new associated item - if ($dataId === $id) - { - $parentModified = $masterModified ?? null; - } - else - { - // Set old modified date from master to existing associated child if not empty - $parentModified = empty($associationsParams[$id]) - ? $masterModified : $associationsParams[$id]; - } - } - else - { - // if modified date isn't set to the child item set it with current modified date from master - $parentModified = empty($associationsParams[$id]) - ? $masterModified : $associationsParams[$id]; + $parentModified = $masterModified ?? null; } } } - // default values + // default values when there is no associated master item else { $parentId = -1; @@ -196,36 +182,51 @@ public static function getMasterLanguageValues( /** * Get the latest modified date of an master item * - * @param integer $masterId Id of the master item - * @param string $table The table name where the item exists + * @param integer $masterId Id of the associated master item + * @param string $tableName The name of the table. + * @param string $typeAlias Alias for the content type * * @return string The modified date of the master item */ - public static function getMasterModifiedDate($masterId, $table) + public static function getMasterModifiedDate($masterId, $tableName, $typeAlias) { - $db = Factory::getDbo(); - - if ($table === '#__categories') - { - $modifiedColumn = 'modified_time'; - } - else - { - $modifiedColumn = 'modified'; - } + // check if the content version is enabled + $option = Factory::getApplication()->input->get('option'); + $saveHistory = ComponentHelper::getParams($option)->get('save_history', 0); if ($masterId) { - $masterDateQuery = $db->getQuery(true) - ->select($db->quoteName($modifiedColumn)) - ->from($db->quoteName($table)) - ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); - $db->setQuery($masterDateQuery); - $masterModified = $db->loadResult(); - - return $masterModified; + // if versions are enabled get the save_data of the master item from history table + if ($saveHistory) + { + $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); + $masterHistory = ContentHistoryHelper::getHistory($masterId, $typeId); + + // latest saved date of the master item + $masterModified = $masterHistory[0]->save_date; + } + else + { + $db = Factory::getDbo(); + + if ($tableName === '#__categories') + { + $modifiedColumn = 'modified_time'; + } + else + { + $modifiedColumn = 'modified'; + } + + $masterDateQuery = $db->getQuery(true) + ->select($db->quoteName($modifiedColumn)) + ->from($db->quoteName($tableName)) + ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); + $db->setQuery($masterDateQuery); + $masterModified = $db->loadResult(); + } } return $masterModified ?? ''; } -} \ No newline at end of file +} diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index 12ab57cdbef98..58f19a7a0c53d 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -686,8 +686,8 @@ public function save($data) // Id of the saved item $dataId = (int) $table->id; - // Get the modified date of master item - $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName()); + // Get the latest modified date of master item + $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName(), $table->typeAlias); // Adding new association for these items $key = md5(json_encode($associations)); diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 2f8f6abff65b9..73f013101d085 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -1368,13 +1368,12 @@ public function save($data) // get id of the item that get saved $dataId = (int) $table->id; - // Get the modified date of master item - $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName()); + // Get the latest modified date of master item + $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName(), $table->typeAlias); // Adding new association for these items $key = md5(json_encode($associations) . $context); - $query = $db->getQuery(true) - ->insert('#__associations'); + $query = $db->getQuery(true)->insert('#__associations'); foreach ($associations as $id) { diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index 7ad825fadb7b2..ef1af5522abd6 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -16,6 +16,7 @@ use Joomla\CMS\Event\BeforeExecuteEvent; use Joomla\CMS\Factory; use Joomla\CMS\Filesystem\Folder; +use Joomla\CMS\Helper\ContentHistoryHelper; use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Language; use Joomla\CMS\Language\LanguageHelper; @@ -24,6 +25,7 @@ use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Router\Route; use Joomla\CMS\Router\Router; +use Joomla\CMS\Table\Table; use Joomla\CMS\Uri\Uri; use Joomla\Component\Menus\Administrator\Helper\MenusHelper; use Joomla\Registry\Registry; @@ -1005,6 +1007,9 @@ public function onExtensionBeforeSave($context, $table, $isNew) $params->global_master_language = ''; } + // check if there were changes for the master language + $this->hasMasterLangChanged = ($params->global_master_language === $this->params->get('global_master_language')) ? false : true; + return $table->params = json_encode($params); } @@ -1031,7 +1036,12 @@ public function onExtensionAfterSave($context, $table, $isNew) return true; } - $this->_setMasterItem($params->global_master_language); + // just set master items when the global master language has changed. + if ($this->hasMasterLangChanged) + { + $this->_setMasterItem($params->global_master_language); + } + unset($this->hasMasterLangChanged); } /** @@ -1049,8 +1059,6 @@ private function _setMasterItem($language) $db = Factory::getDbo(); $masterLanguage = $language; - // TODO add warning when master language changed - // if there is no global masterlanguage set, set all parent_ids to -1 and assocParams to null if (!$masterLanguage) { @@ -1073,8 +1081,6 @@ private function _setMasterItem($language) } else { - // TODO Question? Maybe if the language hasn't changed it isn't necessary to run this again. But no possibility to check that? - // get every different key $keyQuery = $db->getQuery(true) ->select($db->quoteName('key')) @@ -1092,32 +1098,39 @@ private function _setMasterItem($language) ->where($db->quoteName('key') . ' = ' . $db->quote($value)); $assocContext = $db->setQuery($contextQuery)->loadResult(); + $extension = ''; + // get the correct table to look in depending on the context switch ($assocContext) { case 'com_content.item': $fromTable = $db->quoteName('#__content', 'e'); $modified = $db->quoteName('e.modified'); + $typeAlias = 'com_content.article'; break; case 'com_menus.item' : $fromTable = $db->quoteName('#__menu', 'e'); $modified = ''; + $typeAlias = ''; break; case 'com_categories.item': $fromTable = $db->quoteName('#__categories', 'e'); $modified = $db->quoteName('e.modified_time'); + $extension = $db->quoteName('e.extension'); break; case 'com_contact.item': $fromTable = $db->quoteName('#__contact_details', 'e'); $modified = $db->quoteName('e.modified'); + $typeAlias = 'com_contact.contact'; break; case 'com_newsfeeds.item': $fromTable = $db->quoteName('#__newsfeeds', 'e'); $modified = $db->quoteName('e.modified'); + $typeAlias = 'com_newsfeeds.newsfeed'; break; } @@ -1138,11 +1151,39 @@ private function _setMasterItem($language) // Get master modified date if ($modified) { - $masterModQuery = $db->getQuery(true) - ->select($modified) - ->from($fromTable) - ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); - $masterModified = $db->setQuery($masterModQuery)->loadResult(); + // get the context of this category + if($extension){ + $categoryQuery = $db->getQuery(true) + ->select($extension) + ->from($fromTable) + ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); + $categoryMasterExtension = $db->setQuery($categoryQuery)->loadResult(); + $typeAlias = $categoryMasterExtension . '.category'; + } + + // if enabled use the history save_date otherwise use the modified date + $component = $categoryMasterExtension ?? explode('.', $assocContext)[0]; + $saveHistory = ComponentHelper::getParams($component)->get('save_history', 0); + + // if versions are enabled get the save_data of the master item from history table + if ($saveHistory) + { + $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); + $masterHistory = ContentHistoryHelper::getHistory($typeId, $masterId); + + // latest saved date of the master item + $masterModified = $masterHistory[0]->save_date; + } + else + { + $masterModQuery = $db->getQuery(true) + ->select($modified) + ->from($fromTable) + ->where($db->quoteName('id') . ' = ' + . $db->quote($masterId)); + $masterModified = $db->setQuery($masterModQuery) + ->loadResult(); + } } $masterModified = $modified ? $masterModified : null; @@ -1169,7 +1210,7 @@ private function _setMasterItem($language) return; } - // Set the master id to the children + // Set the master id and modified date to the children $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) ->set($db->quoteName('parent_id') . ' = ' . $db->quote($masterId)) diff --git a/plugins/system/languagefilter/languagefilter.xml b/plugins/system/languagefilter/languagefilter.xml index 6b0bc8970fa2a..9ac297c440429 100644 --- a/plugins/system/languagefilter/languagefilter.xml +++ b/plugins/system/languagefilter/languagefilter.xml @@ -44,6 +44,11 @@
+ + + + Date: Sun, 23 Jun 2019 17:11:47 +0200 Subject: [PATCH 25/98] improve filtering by associations state - changed option values to names instead of numbers - no longer displays child elements of a master element that do not match when filtering. --- .../Helper/AssociationsHelper.php | 24 ++++++++++++++++++- .../Model/AssociationsModel.php | 8 +++---- .../forms/filter_associations.xml | 8 +++---- .../tmpl/associations/default.php | 3 ++- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 057c2eb820cfd..d6d4a2f4db2cd 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -212,12 +212,13 @@ private static function getExtensionRealName($extensionName) * @param integer $itemId Item id. * @param string $itemLanguage Item language code. * @param boolean $addLink True for adding edit links. False for just text. + * @param string $assocState The filter association state * * @return string The language HTML * * @since 3.7.0 */ - public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true) + public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true, $assocState) { $globalMasterLanguage = Associations::getGlobalMasterLanguage(); @@ -343,9 +344,21 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC'); $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; $update = true; + + // Don't display not corresponding item + if($assocState !== 'all' && $assocState !== 'outdated'){ + unset($items[$langCode]); + continue; + } } else { + // Don't display not corresponding item + if($assocState !== 'all' && $assocState !== 'up_to_date'){ + unset($items[$langCode]); + continue; + } + $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); } } @@ -380,6 +393,15 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $languageTitle = $language->title . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); $target = ''; } + else + { + // Don't display not corresponding item + if ($assocState !== 'all' && $assocState !== 'not_associated') + { + unset($items[$langCode]); + continue; + } + } // Change target, when there is no association with the global master language for the child item if ($globalMasterLanguage !== $itemLanguage) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 8420d57c19a79..2763058ea932b 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -449,10 +449,10 @@ protected function getListQuery() // Filter by association state $assocStateField = $this->state->get('assocstate'); - if ($assocStateField !== '') + if ($assocStateField !== 'all') { // not associated - if ($assocStateField === '-1') + if ($assocStateField === 'not_associated') { $languageQuery = $db->getQuery(true) ->select('COUNT(*)') @@ -478,7 +478,7 @@ protected function getListQuery() } // outdated - if ($assocStateField === '0') + if ($assocStateField === 'outdated') { // if we are on the masterlanguage and we check the state of the children $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') @@ -489,7 +489,7 @@ protected function getListQuery() } // up-to-date - if ($assocStateField === '1') + if ($assocStateField === 'up_to_date') { // if we are on the masterlanguage and we check the state of the children $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') diff --git a/administrator/components/com_associations/forms/filter_associations.xml b/administrator/components/com_associations/forms/filter_associations.xml index b9c5c103c5e97..8d0f7b84ffa12 100644 --- a/administrator/components/com_associations/forms/filter_associations.xml +++ b/administrator/components/com_associations/forms/filter_associations.xml @@ -26,10 +26,10 @@ onchange="this.form.submit();" > - - - - + + + +
diff --git a/administrator/components/com_associations/tmpl/associations/default.php b/administrator/components/com_associations/tmpl/associations/default.php index 0f79c4f7abb87..25c7b9b519d10 100644 --- a/administrator/components/com_associations/tmpl/associations/default.php +++ b/administrator/components/com_associations/tmpl/associations/default.php @@ -20,6 +20,7 @@ $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); +$assocState = $this->escape($this->state->get('assocstate')); $canManageCheckin = Factory::getUser()->authorise('core.manage', 'com_checkin'); $iconStates = array( @@ -120,7 +121,7 @@ - extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout); ?> + extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout, $assocState); ?> typeFields['menutype'])) : ?> From cb4a7d3d382b2e642a2e42ca0df464871f64b0a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sun, 23 Jun 2019 17:20:46 +0200 Subject: [PATCH 26/98] undo master language activation for multilingual sample data Since it seems difficult to determine whether content versions are enabled or not, conflicts would arise if you simply set the modified date of the master item instead. Therefore, the changes are undone. The master language must now be explicitly activated in the plugin language filter. --- plugins/sampledata/multilang/multilang.php | 16 +++------------- plugins/system/languagefilter/languagefilter.xml | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/plugins/sampledata/multilang/multilang.php b/plugins/sampledata/multilang/multilang.php index 115a74f3f1c03..aa9963c26433c 100644 --- a/plugins/sampledata/multilang/multilang.php +++ b/plugins/sampledata/multilang/multilang.php @@ -14,7 +14,6 @@ use Joomla\CMS\Extension\ExtensionHelper; use Joomla\CMS\Factory; use Joomla\CMS\Installer\Installer; -use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Language; use Joomla\CMS\Language\LanguageHelper; use Joomla\CMS\Language\Text; @@ -512,7 +511,6 @@ private function enablePlugin($pluginName) // Store language filter plugin parameters. if ($pluginName == 'plg_system_languagefilter') { - $currentDefaultLanguage = $this->app->get('language'); $params = '{' . '"detect_browser":"0",' . '"automatic_change":"1",' @@ -520,8 +518,8 @@ private function enablePlugin($pluginName) . '"remove_default_prefix":"0",' . '"lang_cookie":"0",' . '"alternate_meta":"1",' - . '"user_master_language":"1",' - . '"global_master_language":"' . $currentDefaultLanguage . '"' + . '"user_master_language":"0",' + . '"global_master_language":""' . '}'; $query ->clear() @@ -902,24 +900,16 @@ private function addBlogMenuItem($itemLanguage, $categoryId) private function addAssociations($groupedAssociations) { $db = Factory::getDbo(); - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); foreach ($groupedAssociations as $context => $associations) { - // If there is an association item with the globalMasterLanguage, then get his id - $masterId = $associations[$globalMasterLanguage] ?? ''; - // TODO when there is a way to get the history save date from here, use it. - $masterModified = ($context === 'com_menus.item' || !$globalMasterLanguage) ? null : '0000-00-00 00:00:00'; $key = md5(json_encode($associations)); $query = $db->getQuery(true) ->insert('#__associations'); foreach ($associations as $language => $id) { - // If there is no master item in this association, then reset the parent_id to -1 - // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. - $parentId = $masterId ? ($masterId === $id ? 0 : $masterId) : -1; - $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($parentId) . ',' . $db->quote($masterModified)); + $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote('-1') . ',' . $db->quote('')); } $db->setQuery($query); diff --git a/plugins/system/languagefilter/languagefilter.xml b/plugins/system/languagefilter/languagefilter.xml index 9ac297c440429..33a7a810ff633 100644 --- a/plugins/system/languagefilter/languagefilter.xml +++ b/plugins/system/languagefilter/languagefilter.xml @@ -67,7 +67,7 @@ label="PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_LABEL" description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_DESC" class="switcher" - default="1" + default="0" showon="item_associations:1" > From 666acbd00266073550462252173c482760951cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sun, 23 Jun 2019 17:27:27 +0200 Subject: [PATCH 27/98] set default value for the association state filter --- .../components/com_associations/Model/AssociationsModel.php | 2 +- .../com_associations/View/Associations/HtmlView.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 2763058ea932b..b7d912bf04d09 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -107,7 +107,7 @@ protected function populateState($ordering = 'ordering', $direction = 'asc') $this->setState('itemtype', $this->getUserStateFromRequest($this->context . '.itemtype', 'itemtype', $defaultItemType, 'string')); $this->setState('language', $this->getUserStateFromRequest($this->context . '.language', 'language', $defaultLanguage, 'string')); - $this->setState('assocstate', $this->getUserStateFromRequest($this->context . '.assocstate', 'assocstate', '', 'string')); + $this->setState('assocstate', $this->getUserStateFromRequest($this->context . '.assocstate', 'assocstate', 'all', 'string')); $this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string')); $this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'cmd')); $this->setState('filter.category_id', $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '', 'cmd')); diff --git a/administrator/components/com_associations/View/Associations/HtmlView.php b/administrator/components/com_associations/View/Associations/HtmlView.php index 5cac534f150c2..737020e240b1a 100644 --- a/administrator/components/com_associations/View/Associations/HtmlView.php +++ b/administrator/components/com_associations/View/Associations/HtmlView.php @@ -89,6 +89,12 @@ public function display($tpl = null) $this->filterForm->setValue('language', null, $this->state->get('language')); } + // Get default values and set these to selected to the select boxes + if ($this->state->get('assocstate')) + { + $this->filterForm->setValue('assocstate', null, $this->state->get('assocstate')); + } + if (!Associations::isEnabled()) { $link = Route::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . AssociationsHelper::getLanguagefilterPluginId()); From 9b3d1c6913c7444ffca36606c6058fcea0e668e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sun, 23 Jun 2019 17:50:33 +0200 Subject: [PATCH 28/98] fix filter by association state also for modal --- .../components/com_associations/Helper/AssociationsHelper.php | 2 +- .../com_associations/Helper/MasterAssociationsHelper.php | 2 +- .../components/com_associations/tmpl/associations/modal.php | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index d6d4a2f4db2cd..4e90baef789af 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -218,7 +218,7 @@ private static function getExtensionRealName($extensionName) * * @since 3.7.0 */ - public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true, $assocState) + public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true, $assocState = 'all') { $globalMasterLanguage = Associations::getGlobalMasterLanguage(); diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 530bce3191f3e..be2a7de215f40 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -200,7 +200,7 @@ public static function getMasterModifiedDate($masterId, $tableName, $typeAlias) if ($saveHistory) { $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); - $masterHistory = ContentHistoryHelper::getHistory($masterId, $typeId); + $masterHistory = ContentHistoryHelper::getHistory($typeId, $masterId); // latest saved date of the master item $masterModified = $masterHistory[0]->save_date; diff --git a/administrator/components/com_associations/tmpl/associations/modal.php b/administrator/components/com_associations/tmpl/associations/modal.php index ca3e33e837b57..c8ef23946f2c2 100644 --- a/administrator/components/com_associations/tmpl/associations/modal.php +++ b/administrator/components/com_associations/tmpl/associations/modal.php @@ -29,6 +29,7 @@ $function = $app->input->getCmd('function', 'jSelectAssociation'); $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); +$assocState = $this->escape($this->state->get('assocstate')); $canManageCheckin = Factory::getUser()->authorise('core.manage', 'com_checkin'); $iconStates = array( @@ -137,7 +138,7 @@ association) : ?> - extensionName, $this->typeName, (int) $item->id, $item->language, false, false); ?> + extensionName, $this->typeName, (int) $item->id, $item->language, false, $assocState); ?> typeFields['menutype'])) : ?> From dbe749452556fd7ceebb2f3426f79b103e238fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 25 Jun 2019 14:46:17 +0200 Subject: [PATCH 29/98] remove hardcoded table names This finds the table name using the getSupportedExtension function, except for categories. There are also changes for the field description and some comments. Also removed hardcoded error messages. --- .../en-GB/en-GB.plg_system_languagefilter.ini | 2 +- .../system/languagefilter/languagefilter.php | 93 +++++++------------ 2 files changed, 37 insertions(+), 58 deletions(-) diff --git a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini index b234bdfe9ce0a..19edd7d466689 100644 --- a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini +++ b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini @@ -13,7 +13,7 @@ PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_LABEL="Global Master Lang PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_DESC="Note that changing this value will overwrite all existing Master Child relationships with their states." PLG_SYSTEM_LANGUAGEFILTER_FIELD_ITEM_ASSOCIATIONS_LABEL="Item Associations" PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_LABEL="Set a Master Language?" -PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_DESC="When enabled, a master-child relationship is added between the languages, depending on the selected master language. This adds an additional 'outdated' state to a child element depending on its master. If disabled, functions dependent on this data are not available." +PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_DESC="When enabled, a master-child relationship is added between the languages, depending on the selected master language. This adds an additional 'outdated' state to a child element depending on its master. Please enable versions to get a comparison view for outdated items. If this field is disabled, functions dependent on this data are not available." PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LABEL="Add x-default Meta Tag" PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LANGUAGE_LABEL="x-default Language" PLG_SYSTEM_LANGUAGEFILTER_OPTION_DEFAULT_LANGUAGE="Default frontend language" diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index ef1af5522abd6..800b0141386e6 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -27,6 +27,7 @@ use Joomla\CMS\Router\Router; use Joomla\CMS\Table\Table; use Joomla\CMS\Uri\Uri; +use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper; use Joomla\Component\Menus\Administrator\Helper\MenusHelper; use Joomla\Registry\Registry; use Joomla\String\StringHelper; @@ -969,7 +970,7 @@ private function getLanguageCookie() /** * Before Saving extensions * Method is called when an extension is going to be saved - * change parameters for master language because there depends on other parameters + * change parameters for master language because they depends on other parameters * * @param string $context The extension * @param JTable $table DataBase Table object @@ -1045,12 +1046,15 @@ public function onExtensionAfterSave($context, $table, $isNew) } /** - * Method to set the master item of an association as parent and the children get the parent id - * Also reset the modified date of the master item. Master and children will be up-to-date, as they get the same modified date + * Method to set the master of an association. + * This resets all the current master ids and the modified date and set these new. + * Master and children will be up-to-date, as they get the same modified date * * @param string $language The global master language * - * @return void + * @return boolean Returns true on success, false on failure. + * + * @throws \Exception * * @since 4.0.0 */ @@ -1074,9 +1078,7 @@ private function _setMasterItem($language) } catch (ExecutionFailureException $e) { - $this->_message .= Text::_(' , failed to update the master with his childs'); - - return; + return false; } } else @@ -1098,43 +1100,26 @@ private function _setMasterItem($language) ->where($db->quoteName('key') . ' = ' . $db->quote($value)); $assocContext = $db->setQuery($contextQuery)->loadResult(); - $extension = ''; + $checkCategoryComponent = ''; + $component = explode('.', $assocContext)[0]; - // get the correct table to look in depending on the context - switch ($assocContext) + if($component === 'com_categories'){ + $fromTable = $db->quoteName('#__categories', 'e'); + $modified = $db->quoteName('e.modified_time'); + $checkCategoryComponent = $db->quoteName('e.extension'); + } + else { - case 'com_content.item': - $fromTable = $db->quoteName('#__content', 'e'); - $modified = $db->quoteName('e.modified'); - $typeAlias = 'com_content.article'; - break; - - case 'com_menus.item' : - $fromTable = $db->quoteName('#__menu', 'e'); - $modified = ''; - $typeAlias = ''; - break; - - case 'com_categories.item': - $fromTable = $db->quoteName('#__categories', 'e'); - $modified = $db->quoteName('e.modified_time'); - $extension = $db->quoteName('e.extension'); - break; - - case 'com_contact.item': - $fromTable = $db->quoteName('#__contact_details', 'e'); - $modified = $db->quoteName('e.modified'); - $typeAlias = 'com_contact.contact'; - break; - - case 'com_newsfeeds.item': - $fromTable = $db->quoteName('#__newsfeeds', 'e'); - $modified = $db->quoteName('e.modified'); - $typeAlias = 'com_newsfeeds.newsfeed'; - break; + $extension = AssociationsHelper::getSupportedExtension($component); + $extensionType = $extension['helper']->getItemTypes()[0]; + $extensionTable = $extension['types'][$extensionType]->get('details')['tables']; + $tableName = $extensionTable[array_keys($extensionTable)[0]]; + $fromTable = $db->quoteName($tableName, 'e'); + $typeAlias = $component . '.' . $extensionType; + $modified = ($component === 'com_menus') ? '' : $db->quoteName('e.modified'); } - // get items with the global master language + // get ids of items with the global master language $subQuery = $db->getQuery(true) ->select($db->quoteName('e.id')) ->from($fromTable) @@ -1152,20 +1137,20 @@ private function _setMasterItem($language) if ($modified) { // get the context of this category - if($extension){ - $categoryQuery = $db->getQuery(true) - ->select($extension) + if ($checkCategoryComponent) + { + $categoryQuery = $db->getQuery(true) + ->select($checkCategoryComponent) ->from($fromTable) ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); $categoryMasterExtension = $db->setQuery($categoryQuery)->loadResult(); $typeAlias = $categoryMasterExtension . '.category'; } - // if enabled use the history save_date otherwise use the modified date - $component = $categoryMasterExtension ?? explode('.', $assocContext)[0]; + $component = $categoryMasterExtension ?? $component; $saveHistory = ComponentHelper::getParams($component)->get('save_history', 0); - // if versions are enabled get the save_data of the master item from history table + // if versions are enabled get the save_data of the master item from history table otherwise use the modified date if ($saveHistory) { $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); @@ -1179,10 +1164,8 @@ private function _setMasterItem($language) $masterModQuery = $db->getQuery(true) ->select($modified) ->from($fromTable) - ->where($db->quoteName('id') . ' = ' - . $db->quote($masterId)); - $masterModified = $db->setQuery($masterModQuery) - ->loadResult(); + ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); + $masterModified = $db->setQuery($masterModQuery)->loadResult(); } } @@ -1205,9 +1188,7 @@ private function _setMasterItem($language) } catch (ExecutionFailureException $e) { - $this->_message .= Text::_(' , failed to update the master with his childs'); - - return; + return false; } // Set the master id and modified date to the children @@ -1226,12 +1207,10 @@ private function _setMasterItem($language) } catch (ExecutionFailureException $e) { - $this->_message .= Text::_(' , failed to update the master with his childs'); - - return; + return false; } - } } + return true; } } From 28010b8b0981625e2def5b31dac46f20597c29d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 25 Jun 2019 15:49:51 +0200 Subject: [PATCH 30/98] update outdated child of a master item This adds a new edit view for updating a child item when it is oudated with the master item. There it is just possible to save the target and update his masters modified date. When versions are enabled for this itemtype then there is a compare view displayed for the reference/master otherwise the edit view is displayed. --- .../AssociationMasterController.php | 41 +++++++++ .../Helper/AssociationsHelper.php | 4 +- .../Helper/MasterAssociationsHelper.php | 4 +- .../Model/AssociationMasterModel.php | 72 +++++++++++++++ .../Model/AssociationModel.php | 53 +++++++++++ .../View/Association/HtmlView.php | 50 +++++++---- .../tmpl/association/update.php | 75 ++++++++++++++++ .../tmpl/compare/compareMaster.php | 90 +++++++++++++++++++ .../language/en-GB/en-GB.com_associations.ini | 2 + .../com_associations/css/sidebyside.css | 15 ++++ .../js/admin-compare-master.es6.js | 47 ++++++++++ .../js/sidebysideupdate.es6.js | 66 ++++++++++++++ 12 files changed, 502 insertions(+), 17 deletions(-) create mode 100644 administrator/components/com_associations/Controller/AssociationMasterController.php create mode 100644 administrator/components/com_associations/Model/AssociationMasterModel.php create mode 100644 administrator/components/com_associations/tmpl/association/update.php create mode 100644 administrator/components/com_contenthistory/tmpl/compare/compareMaster.php create mode 100644 build/media_source/com_associations/js/admin-compare-master.es6.js create mode 100644 build/media_source/com_associations/js/sidebysideupdate.es6.js diff --git a/administrator/components/com_associations/Controller/AssociationMasterController.php b/administrator/components/com_associations/Controller/AssociationMasterController.php new file mode 100644 index 0000000000000..14c48311dfa72 --- /dev/null +++ b/administrator/components/com_associations/Controller/AssociationMasterController.php @@ -0,0 +1,41 @@ +input->get('targetId', '', 'int'); + $masterId = $this->input->get('id', '' , 'int'); + $itemtype = $this->input->get('itemtype', '', 'string'); + + $this->getModel('associationmaster')->update($targetId, $masterId, $itemtype); + + $this->setRedirect(Route::_('index.php?option=com_associations&view=associations', false)); + } +} \ No newline at end of file diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 4e90baef789af..488f26dbe77a5 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -244,6 +244,8 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId // Create associated items list. foreach ($languages as $langCode => $language) { + $update = false; + // Don't do for the reference language, when there is no master language set if ($langCode == $itemLanguage && !$globalMasterLanguage) { @@ -415,7 +417,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $options = array( 'option' => 'com_associations', 'view' => 'association', - 'layout' => 'edit', + 'layout' => $update ? 'update' : 'edit', 'itemtype' => $extensionName . '.' . $typeName, 'task' => 'association.edit', 'id' => $masterId ?? $itemId, diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index be2a7de215f40..47fa6f1c6d5b4 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -26,7 +26,9 @@ class MasterAssociationsHelper extends ContentHelper { /** - * @param $globalMasterLanguage + * Method to create a link for a child item that has no master item + * + * @param string $globalMasterLanguage The global master language * * @return string */ diff --git a/administrator/components/com_associations/Model/AssociationMasterModel.php b/administrator/components/com_associations/Model/AssociationMasterModel.php new file mode 100644 index 0000000000000..a0458fe8d606c --- /dev/null +++ b/administrator/components/com_associations/Model/AssociationMasterModel.php @@ -0,0 +1,72 @@ +getQuery(true) + ->select($db->quoteName('assocParams')) + ->from($db->quoteName('#__associations')) + ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('parent_id') . ' = ' . $db->quote(0)) + ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + $masterModified = $db->setQuery($subQuery)->loadResult(); + + $query = $db->getQuery(true) + ->update($db->quoteName('#__associations')) + ->set($db->quoteName('assocParams') . ' = ' . $db->quote($masterModified)) + ->where($db->quoteName('id') . ' = ' . $db->quote($childId)) + ->where($db->quoteName('parent_id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + $db->setQuery($query); + + try + { + $db->execute(); + } + catch (ExecutionFailureException $e) + { + return false; + } + + return true; + } +} \ No newline at end of file diff --git a/administrator/components/com_associations/Model/AssociationModel.php b/administrator/components/com_associations/Model/AssociationModel.php index 8ed1685a28658..57fd64515135c 100644 --- a/administrator/components/com_associations/Model/AssociationModel.php +++ b/administrator/components/com_associations/Model/AssociationModel.php @@ -11,6 +11,7 @@ defined('_JEXEC') or die; +use Joomla\CMS\Factory; use Joomla\CMS\MVC\Model\ListModel; /** @@ -37,4 +38,56 @@ public function getForm($data = array(), $loadData = true) return !empty($form) ? $form : false; } + + /** + * Method to get the history version ids of a master item. + * + * @param integer $masterId Id of the master item + * @param integer $targetId Id of an child item + * @param string $extensionName The extension name with com_ + * @param string $typeName The item type + * @param integer $typeId the content type id + * + * @return array of version history ids + */ + public function getMasterCompareValues($masterId, $targetId, $extensionName, $typeName, $typeId){ + + $context = ($typeName === 'category') + ? 'com_categories.item' + : $extensionName . '.item'; + + $db = Factory::getDbo(); + $masterQuery = $db->getQuery(true) + ->select($db->quoteName('assocParams')) + ->from($db->quoteName('#__associations')) + ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + $latestMasterDate = $db->setQuery($masterQuery)->loadResult(); + + $latestVersionQuery = $db->getQuery(true) + ->select($db->quoteName('version_id')) + ->from($db->quoteName('#__ucm_history')) + ->where($db->quoteName('ucm_item_id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('ucm_type_id') . ' = ' . $db->quote($typeId)) + ->where($db->quoteName('save_date') . ' = ' . $db->quote($latestMasterDate)); + $latestVersionId = $db->setQuery($latestVersionQuery)->loadResult(); + + $childQuery = $db->getQuery(true) + ->select($db->quoteName('assocParams')) + ->from($db->quoteName('#__associations')) + ->where($db->quoteName('id') . ' = ' . $db->quote($targetId)) + ->where($db->quoteName('parent_id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + $childMasterDate = $db->setQuery($childQuery)->loadResult(); + + $olderVersionQuery = $db->getQuery(true) + ->select($db->quoteName('version_id')) + ->from($db->quoteName('#__ucm_history')) + ->where($db->quoteName('ucm_item_id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('ucm_type_id') . ' = ' . $db->quote($typeId)) + ->where($db->quoteName('save_date') . ' = ' . $db->quote($childMasterDate)); + $olderVersionId = $db->setQuery($olderVersionQuery)->loadResult(); + + return [$latestVersionId, $olderVersionId]; + } } diff --git a/administrator/components/com_associations/View/Association/HtmlView.php b/administrator/components/com_associations/View/Association/HtmlView.php index c59abab1a6fb0..1f5b6d10a3b0d 100644 --- a/administrator/components/com_associations/View/Association/HtmlView.php +++ b/administrator/components/com_associations/View/Association/HtmlView.php @@ -11,10 +11,12 @@ defined('_JEXEC') or die; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\Router\Route; +use Joomla\CMS\Table\Table; use Joomla\CMS\Toolbar\Toolbar; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper; @@ -206,24 +208,42 @@ protected function addToolbar() ToolbarHelper::title(Text::sprintf('COM_ASSOCIATIONS_TITLE_EDIT', Text::_($this->extensionName), Text::_($languageKey)), 'contract assoc'); - $bar = Toolbar::getInstance('toolbar'); + $toolbar = Toolbar::getInstance('toolbar'); - $bar->appendButton( - 'Custom', '', 'reference' - ); - - $bar->appendButton( - 'Custom', '', 'target' - ); - - if ($this->typeName === 'category' || $this->extensionName === 'com_menus' || $this->save2copy === true) + // In the update view we can just save the target and when saving the other button gets activated via js to update master information for the child + if($this->getLayout() === 'update') { - ToolbarHelper::custom('copy', 'copy.png', '', 'COM_ASSOCIATIONS_COPY_REFERENCE', false); + $toolbar->appendButton( + 'Custom', '', 'target' + ); + + $toolbar->appendButton( + 'Custom', '', 'target' + ); } + else + { + $toolbar->appendButton( + 'Custom', '', + 'reference' + ); + + $toolbar->appendButton( + 'Custom', '', 'target' + ); + + if ($this->typeName === 'category' || $this->extensionName === 'com_menus' || $this->save2copy === true) + { + ToolbarHelper::custom('copy', 'copy.png', '', 'COM_ASSOCIATIONS_COPY_REFERENCE', false); + } + } + ToolbarHelper::cancel('association.cancel', 'JTOOLBAR_CLOSE'); ToolbarHelper::help('JHELP_COMPONENTS_ASSOCIATIONS_EDIT'); diff --git a/administrator/components/com_associations/tmpl/association/update.php b/administrator/components/com_associations/tmpl/association/update.php new file mode 100644 index 0000000000000..9d0b932a5ec2b --- /dev/null +++ b/administrator/components/com_associations/tmpl/association/update.php @@ -0,0 +1,75 @@ + 'auto', 'relative' => true]); +//HTMLHelper::_('script', 'com_associations/sidebyside.js', ['version' => 'auto', 'relative' => true]); +HTMLHelper::_('stylesheet', 'com_associations/sidebyside.css', ['version' => 'auto', 'relative' => true]); + +$options = array( + 'layout' => $this->app->input->get('layout', '', 'string'), + 'itemtype' => $this->itemtype, + 'id' => $this->referenceId, + 'targetId' => $this->targetId +); +?> + +
+
+
+ referenceVersionIdNew)) : ?> +

+ + +

+ + +
+
+
+
+

+ +
+
+
+ + + diff --git a/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php b/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php new file mode 100644 index 0000000000000..2dd4fbdef7a23 --- /dev/null +++ b/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php @@ -0,0 +1,90 @@ +items[0]; +$version1 = $this->items[1]; +$object1 = $version1->data; +$object2 = $version2->data; + +HTMLHelper::_('script', 'vendor/diff/diff.min.js', array('version' => 'auto', 'relative' => true)); +HTMLHelper::_('script', 'com_associations/admin-compare-master.min.js', array('version' => 'auto', 'relative' => true)); +HTMLHelper::_('stylesheet', 'com_associations/sidebyside.css', ['version' => 'auto', 'relative' => true]); +?> + +
+
+
+ data->title->label ?> +
+
+ +
+
+
+
+ data->alias->label ?> +
+
+ +
+
+
+
+ + + + + + + + + $value) : ?> + value != $object2->$name->value) : ?> + + value)) : ?> + + value as $subName => $subValue) : ?> + $name->value->$subName->value ?? ''; ?> + value || $newSubValue) : ?> + value != $newSubValue) : ?> + + + + + + + + + + + + + $name->value = is_object($object2->$name->value) ? json_encode($object2->$name->value) : $object2->$name->value; ?> + + + + + + + +
+ label; ?> +
label; ?>
+ label; ?> +
+ +
diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index 5791f7b2f57a5..d53242d0bc015 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -37,8 +37,10 @@ COM_ASSOCIATIONS_PURGE_FAILED="Failed to delete all associations." COM_ASSOCIATIONS_PURGE_NONE="There were no associations to delete." COM_ASSOCIATIONS_PURGE_SUCCESS="All associations have been deleted." COM_ASSOCIATIONS_REFERENCE_ITEM="Reference" +COM_ASSOCIATIONS_REFERENCE_ITEM_COMPARE_VIEW="Reference - Compare View" COM_ASSOCIATIONS_SAVE_REFERENCE="Save Reference" COM_ASSOCIATIONS_SAVE_TARGET="Save Target" +COM_ASSOCIATIONS_SAVE_AND_UPDATE_TARGET="Update Target and Close" COM_ASSOCIATIONS_SELECT_MENU="- Select Menu -" COM_ASSOCIATIONS_SELECT_TARGET="Select Target" COM_ASSOCIATIONS_SELECT_TARGET_LANGUAGE="- Select Target Language -" diff --git a/build/media_source/com_associations/css/sidebyside.css b/build/media_source/com_associations/css/sidebyside.css index c2ddde2af6da2..27df7eb024842 100644 --- a/build/media_source/com_associations/css/sidebyside.css +++ b/build/media_source/com_associations/css/sidebyside.css @@ -58,6 +58,21 @@ html[dir=rtl] .target-text { float: right; } +.diff .added { + background-color: #a6f3a6; + border-radius: .2rem; +} + +.diff .removed { + background-color: #f8cbcb; + border-radius: .2rem; +} + +.diff .same { + background-color: unset; + border-radius: 0; +} + /* Responsive layout */ @media (max-width: 767px) { .sidebyside .outer-panel { diff --git a/build/media_source/com_associations/js/admin-compare-master.es6.js b/build/media_source/com_associations/js/admin-compare-master.es6.js new file mode 100644 index 0000000000000..950b0eae6b86b --- /dev/null +++ b/build/media_source/com_associations/js/admin-compare-master.es6.js @@ -0,0 +1,47 @@ +/** + * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ +(() => { + 'use strict'; + + const compare = (original, changed) => { + const display = changed.nextElementSibling; + let className = 'same'; + let tagName = 'mark'; + let tagElement = null; + + const diff = window.JsDiff.diffWords(original.textContent, changed.textContent); + const fragment = document.createDocumentFragment(); + + diff.forEach((part) => { + if (part.added) { + className = 'added'; + } + + if (part.removed) { + className = 'removed'; + } + + tagElement = document.createElement(tagName); + tagElement.setAttribute('class', className); + tagElement.appendChild(document.createTextNode(part.value)); + fragment.appendChild(tagElement); + }); + + display.appendChild(fragment); + console.log(display); + }; + + const onBoot = () => { + const diffs = [].slice.call(document.querySelectorAll('.original')); + diffs.forEach((fragment) => { + compare(fragment, fragment.nextElementSibling); + }); + + // Cleanup + document.removeEventListener('DOMContentLoaded', onBoot); + }; + + document.addEventListener('DOMContentLoaded', onBoot); +})(); diff --git a/build/media_source/com_associations/js/sidebysideupdate.es6.js b/build/media_source/com_associations/js/sidebysideupdate.es6.js new file mode 100644 index 0000000000000..75f910a4a9f4c --- /dev/null +++ b/build/media_source/com_associations/js/sidebysideupdate.es6.js @@ -0,0 +1,66 @@ +/** + * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ +Joomla = window.Joomla || {}; + +((Joomla, document) => { + 'use strict'; + + document.addEventListener('DOMContentLoaded', () => { + + const referenceIframe = document.getElementById('reference-association'); + const targetIframe = document.getElementById('target-association'); + + // Saving target, send the save action to the target iframe. + Joomla.submitbutton = (task) => { + // Using close button, normal joomla submit. + if (task === 'association.cancel') { + Joomla.submitform(task); + } else if (task === 'associationmaster.update') { + Joomla.submitform(task); + } else { + window.frames['target-association'].Joomla.submitbutton(document.getElementById('adminForm').getAttribute('data-associatedview') + '.apply'); + document.getElementById("updateChild").click(); + } + }; + + // Attach behaviour to reference frame load event. + referenceIframe.addEventListener('load', () => { + const reference = referenceIframe.contentDocument; + const referenceDiff = reference.querySelector('#diff'); + // Waiting until the reference has loaded before loading the target to avoid race conditions + let targetURL = Joomla.getOptions('targetSrc', false); + + if (referenceDiff) { + + } else { + // Disable language field. + reference.querySelector('#jform_language').setAttribute('disabled', ''); + + // Remove modal buttons on the reference + reference.querySelector('#associations').querySelectorAll('.btn').forEach(e => e.parentNode.removeChild(e)); + } + + // Iframe load finished, hide Joomla loading layer. + Joomla.loadingLayer('hide'); + }); + + targetIframe.addEventListener('load', () => { + + if (targetIframe.getAttribute('src') != '') { + const targetLanguage = targetIframe.getAttribute('data-language'); + const targetId = targetIframe.getAttribute('data-id'); + const target = targetIframe.contentDocument; + const targetLoadedId = target.querySelector('#jform_id').value || '0'; + + // Update language field with the selected language and then disable it. + target.querySelector('#jform_language').setAttribute('disabled', ''); + + // Iframe load finished, hide Joomla loading layer. + Joomla.loadingLayer('hide'); + } + + }); + }); +})(Joomla, document); \ No newline at end of file From b74287ec2c8d6e8ab8f2ac3798c3986a2e5379dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 25 Jun 2019 15:52:00 +0200 Subject: [PATCH 31/98] add forgotten file for update outdated child of a master item --- .../View/Association/HtmlView.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/administrator/components/com_associations/View/Association/HtmlView.php b/administrator/components/com_associations/View/Association/HtmlView.php index 1f5b6d10a3b0d..cc648c4205bc7 100644 --- a/administrator/components/com_associations/View/Association/HtmlView.php +++ b/administrator/components/com_associations/View/Association/HtmlView.php @@ -170,6 +170,23 @@ public function display($tpl = null) $this->targetTitle = AssociationsHelper::getTypeFieldName($extensionName, $typeName, 'title'); $task = $typeName . '.' . $this->targetAction; + // get version ids of the master item, when versions are enabled. + if($this->getLayout() === 'update'){ + $saveHistory = ComponentHelper::getParams($extensionName)->get('save_history', 0); + + if($saveHistory) + { + $typeAlias = $typeName === 'category' ? $extensionName . '.' . $typeName : $reference['typeAlias']; + $model = $this->getModel(); + $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); + $masterVersionIds = $model->getMasterCompareValues($referenceId, $this->targetId, $extensionName, $typeName, $typeId); + if ($masterVersionIds[0] !== null && $masterVersionIds[1] !== null) + { + $this->referenceVersionIdNew = $masterVersionIds[0]; + $this->referenceVersionIdOld = $masterVersionIds[1]; + } + } + } /* * Let's put the target src into a variable to use in the javascript code * to avoid race conditions when the reference iframe loads. From b34c098c0cee931e128db884f56a42509fb133a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 25 Jun 2019 15:53:16 +0200 Subject: [PATCH 32/98] remove unused functions, change function name and change comments --- .../Helper/MasterAssociationsHelper.php | 50 +++---------------- .../com_categories/Model/CategoryModel.php | 2 +- libraries/src/MVC/Model/AdminModel.php | 2 +- 3 files changed, 8 insertions(+), 46 deletions(-) diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 47fa6f1c6d5b4..7321d6b40c14d 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -30,7 +30,7 @@ class MasterAssociationsHelper extends ContentHelper * * @param string $globalMasterLanguage The global master language * - * @return string + * @return string the link for the not associated master item */ public static function addNotAssociatedMasterLink($globalMasterLanguage) { @@ -44,7 +44,8 @@ public static function addNotAssociatedMasterLink($globalMasterLanguage) $globalMasterLanguageInfos = $db->loadAssoc(); $classes = 'hasPopover badge badge-secondary'; - $languageTitle = $globalMasterLanguageInfos['title'] . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); + $languageTitle = $globalMasterLanguageInfos['title'] . ' - ' + . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); $text = $globalMasterLanguageInfos['sef'] ? strtoupper($globalMasterLanguageInfos['sef']) : 'XX'; @@ -59,47 +60,6 @@ public static function addNotAssociatedMasterLink($globalMasterLanguage) return $link; } - /** - * @param integer $itemId Item id - * @param string $context Context of the association - * - * @return boolean True if the item is a master item, false otherwise - */ - public static function isMaster($itemId, $context) - { - $parentId = self::getMasterId($itemId, $context); - - $isMaster = ($parentId === 0) ? true : false; - - return $isMaster; - - } - - /** - * Get the associated master item id from a child element. - * - * @param integer $itemId Item id - * @param string $context context of the association - * - * @return integer The id of the associated master item - * - * @since 4.0 - */ - public static function getMasterId($itemId, $context) - { - $db = Factory::getDbo(); - - $parentQuery = $db->getQuery(true) - ->select($db->quoteName('parent_id')) - ->from($db->quoteName('#__associations')) - ->where($db->quoteName('id') . ' = ' . $db->quote($itemId)) - ->where($db->quoteName('context') . ' = ' . $db->quote($context)); - $masterId = $db->setQuery($parentQuery)->loadResult(); - - return (int) $masterId; - - } - /** * Method to get associated params of the master item. * @@ -134,6 +94,8 @@ public static function getAssociationsParams($associations, $context) } /** + * Method to set parent_id and modified date of an association that get to be saved + * * @param integer $id Item id * @param integer $dataId Item id of an item that is going to be saved * @param integer $masterId Id of the associated master item @@ -143,7 +105,7 @@ public static function getAssociationsParams($associations, $context) * * @return array parent id and modified date */ - public static function getMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $old_key) { + public static function setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $old_key) { if ($masterId) { diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index 58f19a7a0c53d..70937197eef53 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -696,7 +696,7 @@ public function save($data) foreach ($associations as $id) { - $masterValues = MasterAssociationsHelper::getMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $oldKey); + $masterValues = MasterAssociationsHelper::setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $oldKey); $parentId = $masterValues[0]; $parentModified = $masterValues[1]; diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 73f013101d085..61d807a3fbc04 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -1377,7 +1377,7 @@ public function save($data) foreach ($associations as $id) { - $masterValues = MasterAssociationsHelper::getMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $old_key); + $masterValues = MasterAssociationsHelper::setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $old_key); $parentId = $masterValues[0]; $parentModified = $masterValues[1]; From 591ced4a0e405d3d42fdded1677d26dac18a56b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 1 Jul 2019 14:05:11 +0200 Subject: [PATCH 33/98] revert some changes and adjust tooltips in List Views with Associations This revert the following changes when no master language is used: - the column 'Not Associated' in Associations is back - centering the associations column in all list views has been reverted Changes for List Views when a global master language is set: - centering the associations column in all list views - the toolip has been adjusted - - check if versions are enabled, if not the text for outdated items has been adjusted to "might be outdated" as we have no comparison if there has been made changes when the master item has been saved. So the user has to check manually if the child is really outdated. But he knows now that the master item has been saved at least. --- .../Helper/AssociationsHelper.php | 76 ++++++++++++++----- .../Helper/MasterAssociationsHelper.php | 33 ++++---- .../View/Association/HtmlView.php | 5 +- .../tmpl/associations/default.php | 28 ++++++- .../tmpl/associations/modal.php | 2 +- .../tmpl/categories/default.php | 6 +- .../Service/HTML/AdministratorService.php | 28 ++++--- .../com_contact/tmpl/contacts/default.php | 4 +- .../Service/HTML/AdministratorService.php | 25 +++--- .../com_content/tmpl/articles/default.php | 4 +- .../Service/HTML/AdministratorService.php | 27 ++++--- .../language/en-GB/en-GB.com_associations.ini | 2 + administrator/language/en-GB/en-GB.ini | 3 +- .../templates/atum/scss/template.scss | 16 +++- .../js/admin-compare-master.es6.js | 1 - .../js/sidebysideupdate.es6.js | 3 + layouts/joomla/content/associations.php | 39 +++++----- 17 files changed, 197 insertions(+), 105 deletions(-) diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 62f7618840025..10ab578867d63 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -13,6 +13,7 @@ use Joomla\CMS\Association\AssociationExtensionInterface; use Joomla\CMS\Association\AssociationServiceInterface; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Associations; @@ -211,23 +212,28 @@ private static function getExtensionRealName($extensionName) * @param integer $itemId Item id. * @param string $itemLanguage Item language code. * @param boolean $addLink True for adding edit links. False for just text. - * @param string $assocState The filter association state + * @param boolean $assocLanguages True for showing non associated content languages. False only languages with associations. + * @param string $assocState The filter association state, enabled when a global master language is used * * @return string The language HTML * * @since 3.7.0 */ - public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true, $assocState = 'all') + public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true, $assocLanguages = true, $assocState = 'all') { + // Get the global master language, empty if not used $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + // Check if versions are enabled + $saveHistory = ComponentHelper::getParams($extensionName)->get('save_history', 0); + // Get the associations list for this item. $items = self::getAssociationList($extensionName, $typeName, $itemId); $context = ($typeName === 'category') ? 'com_categories.item' : $extensionName . '.item'; - // Get association params if there are associated items if ($items) { + // Get master dates of each item of an association $assocParams = MasterAssociationsHelper::getAssociationsParams($items, $context); $masterId = $items[$globalMasterLanguage]['id'] ?? null; } @@ -246,12 +252,28 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $update = false; $masterInfo = ''; - // Don't do for the reference language, when there is no master language set - if ($langCode == $itemLanguage && !$globalMasterLanguage) + if(!$globalMasterLanguage) + { + // Don't do for the reference language + if ($langCode == $itemLanguage) { continue; } + // Don't show languages with associations, if we don't want to show them. + if ($assocLanguages && isset($items[$langCode])) + { + unset($items[$langCode]); + continue; + } + + // Don't show languages without associations, if we don't want to show them. + if (!$assocLanguages && !isset($items[$langCode])) + { + continue; + } + } + // Get html parameters for associated items if (isset($items[$langCode])) { @@ -300,22 +322,19 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId } $labelClass = 'badge-success'; - $languageTitle = $language->title; $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; $allow = $canEditReference && self::allowEdit($extensionName, $typeName, $items[$langCode]['id']) && self::canCheckinItem($extensionName, $typeName, $items[$langCode]['id']); - $additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : ''; - - if ($globalMasterLanguage) { // Settings for the master language if ($globalMasterLanguage === $langCode) { $labelClass .= ' master-item'; - $masterInfo = Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM') . '

'; + $additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : ''; + $masterInfo = '

' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); if ($globalMasterLanguage === $itemLanguage) { @@ -342,16 +361,23 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId if ($associatedModifiedMaster < $lastModifiedMaster) { - $labelClass = 'badge-warning'; - $masterInfo = Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') . '

'; - $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; - $update = true; - // Don't display not corresponding item if($assocState !== 'all' && $assocState !== 'outdated'){ unset($items[$langCode]); continue; } + + $additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_UPDATE_ASSOCIATION') : ''; + $labelClass = 'badge-warning'; + $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; + $update = true; + + // when versions are disabled than the modified date is used for the master item. + // That means that when no changes were made and the master item has been saved the modified date has been changed. + // So the outdated state means in that case there might have been made changes and it is necessary to check manually and update the target. + $masterInfo = $saveHistory + ? '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') + : '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); } else { @@ -361,11 +387,22 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId continue; } - $masterInfo = Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC') . '

'; + $additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : ''; + $masterInfo = '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); + + // for item types that do not use modified date or versions like menu items + if (!$associatedModifiedMaster) + { + $masterInfo = ''; + } } } } } + else + { + $additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : ''; + } } // Get html parameters for not associated items else @@ -385,14 +422,13 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $labelClass = 'badge-secondary'; $target = $langCode . ':0:add'; $allow = $canCreate; - $languageTitle = $language->title; if ($globalMasterLanguage) { if ($globalMasterLanguage === $langCode) { $labelClass .= ' master-item'; - $masterInfo = Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM') . '

'; + $masterInfo = '

' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); $target = ''; } else @@ -429,10 +465,10 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $text = strtoupper($language->sef); $tooltip = '' . htmlspecialchars($language->title, ENT_QUOTES, 'UTF-8') . '
' - . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '

' . $masterInfo . $additional; + . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '

' . $additional . $masterInfo; $classes = 'badge ' . $labelClass; - $items[$langCode]['link'] = '' . $text . '' + $items[$langCode]['link'] = '' . $text . '' . '
' . $tooltip . '
'; // Reorder the array, so the master item gets to the first place diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 7321d6b40c14d..15109740645a5 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -44,30 +44,29 @@ public static function addNotAssociatedMasterLink($globalMasterLanguage) $globalMasterLanguageInfos = $db->loadAssoc(); $classes = 'hasPopover badge badge-secondary'; - $languageTitle = $globalMasterLanguageInfos['title'] . ' - ' - . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); + $masterInfo = '

' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); $text = $globalMasterLanguageInfos['sef'] ? strtoupper($globalMasterLanguageInfos['sef']) : 'XX'; $title = Text::_('JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC'); - $tooltip = htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); $url = ''; - $link = '' . $text . ''; + $tooltip = '' . htmlspecialchars( $globalMasterLanguageInfos['title'], ENT_QUOTES, 'UTF-8') . '
' + . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . $masterInfo; + + $link = '' . $text . '' + . ''; return $link; } /** - * Method to get associated params of the master item. + * Method to get master dates for each item of an association. * * @param array $associations the associations to be saved. - * * @param string $context the association context * - * @return array associations with params + * @return array association with master dates * */ public static function getAssociationsParams($associations, $context) @@ -94,16 +93,16 @@ public static function getAssociationsParams($associations, $context) } /** - * Method to set parent_id and modified date of an association that get to be saved + * Method to set master_id and master_date for an association that get to be saved * - * @param integer $id Item id - * @param integer $dataId Item id of an item that is going to be saved - * @param integer $masterId Id of the associated master item - * @param string $masterModified the latest modified date of the master - * @param array $associationsParams modified date to associated items - * @param string $old_key the old association key + * @param integer $id Item id + * @param integer $dataId Item id of an item that is going to be saved + * @param integer $masterId Id of the associated master item + * @param string $masterModified The latest modified date of the master + * @param array $assocMasterDates Masters modified date of an associated item + * @param string $old_key The old association key to check if it is a new association * - * @return array parent id and modified date + * @return array master id and master dates for an associated item */ public static function setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $old_key) { diff --git a/administrator/components/com_associations/View/Association/HtmlView.php b/administrator/components/com_associations/View/Association/HtmlView.php index 603d388ac2281..35b9098d0e0f5 100644 --- a/administrator/components/com_associations/View/Association/HtmlView.php +++ b/administrator/components/com_associations/View/Association/HtmlView.php @@ -170,6 +170,7 @@ public function display($tpl = null) $this->targetTitle = AssociationsHelper::getTypeFieldName($extensionName, $typeName, 'title'); $task = $typeName . '.' . $this->targetAction; + // The update layout can only be set when a global master language is used. // get version ids of the master item, when versions are enabled. if($this->getLayout() === 'update'){ $saveHistory = ComponentHelper::getParams($extensionName)->get('save_history', 0); @@ -227,15 +228,17 @@ protected function addToolbar() $toolbar = Toolbar::getInstance('toolbar'); - // In the update view we can just save the target and when saving the other button gets activated via js to update master information for the child + // The update layout can only be set when a global master language is used. if($this->getLayout() === 'update') { + // In the update view we can just save the target $toolbar->appendButton( 'Custom', '', 'target' ); + // and when saving the target this button gets activated via js to update the master date for the child $toolbar->appendButton( 'Custom', '', 'target' ); diff --git a/administrator/components/com_associations/tmpl/associations/default.php b/administrator/components/com_associations/tmpl/associations/default.php index 25c7b9b519d10..89ffa6464cec7 100644 --- a/administrator/components/com_associations/tmpl/associations/default.php +++ b/administrator/components/com_associations/tmpl/associations/default.php @@ -11,6 +11,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; @@ -20,8 +21,9 @@ $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); +$canManageCheckin = Factory::getUser()->authorise('core.manage', 'com_checkin'); +$globalMasterLanguage = Associations::getGlobalMasterLanguage(); $assocState = $this->escape($this->state->get('assocstate')); -$canManageCheckin = Factory::getUser()->authorise('core.manage', 'com_checkin'); $iconStates = array( -2 => 'icon-trash', @@ -59,9 +61,18 @@ - + + + + + + + + + + typeFields['menutype'])) : ?> @@ -120,9 +131,18 @@ - - extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout, $assocState); ?> + + + extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout, true, $assocState); ?> + + + + extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout, false); ?> + + + extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout, true); ?> + typeFields['menutype'])) : ?> escape($item->menutype_title); ?> diff --git a/administrator/components/com_associations/tmpl/associations/modal.php b/administrator/components/com_associations/tmpl/associations/modal.php index 9240db9745c7d..35ffc1821ed52 100644 --- a/administrator/components/com_associations/tmpl/associations/modal.php +++ b/administrator/components/com_associations/tmpl/associations/modal.php @@ -132,7 +132,7 @@ association) : ?> - extensionName, $this->typeName, (int) $item->id, $item->language, false, $assocState); ?> + extensionName, $this->typeName, (int) $item->id, $item->language, false, false, $assocState); ?> typeFields['menutype'])) : ?> diff --git a/administrator/components/com_categories/tmpl/categories/default.php b/administrator/components/com_categories/tmpl/categories/default.php index 3b517f6bf73d7..51526bb84717f 100644 --- a/administrator/components/com_categories/tmpl/categories/default.php +++ b/administrator/components/com_categories/tmpl/categories/default.php @@ -11,6 +11,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; @@ -29,6 +30,7 @@ $parts = explode('.', $extension, 2); $component = $parts[0]; $section = null; +$masterAlign = Associations::getGlobalMasterLanguage() ? 'text-center ' : ''; if (count($parts) > 1) { @@ -108,7 +110,7 @@ assoc) : ?> - + @@ -231,7 +233,7 @@ escape($item->access_level); ?> assoc) : ?> - + association) : ?> id, $extension); ?> diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index b8e78b74816de..2d71e91e83a42 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -11,6 +11,7 @@ defined('_JEXEC') or die; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Associations; @@ -39,9 +40,13 @@ class AdministratorService public function association($contactid) { // Defaults - $html = ''; + $html = ''; + $masterInfo = ''; $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + // Check if versions are enabled + $saveHistory = ComponentHelper::getParams('com_contact')->get('save_history', 0); + // Get the associations if ($associations = Associations::getAssociations('com_contact', '#__contact_details', 'com_contact.item', $contactid)) { @@ -82,7 +87,7 @@ public function association($contactid) if ($globalMasterLanguage) { - // Check whether the current article is written in the global master language + // Check whether the current contact is written in the global master language $masterElement = (array_key_exists($contactid, $items) && ($items[$contactid]->lang_code === $globalMasterLanguage)) ? true @@ -101,15 +106,13 @@ public function association($contactid) foreach ($items as $key => &$item) { $labelClass = 'badge-success'; - $languageTitle = $item->language_title; $text = strtoupper($item->lang_sef); - $title = $item->title; $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); if ($globalMasterLanguage) { - // Don't continue for master, because it has been set here before + // Don't continue for master, because it has been set just before as new array item if ($key === 'master') { continue; @@ -126,7 +129,8 @@ public function association($contactid) if ($key === $masterId) { $labelClass .= ' master-item'; - $languageTitle = $item->language_title . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); + $masterInfo = '

' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); + $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); } else { @@ -139,21 +143,23 @@ public function association($contactid) if ($associatedModifiedMaster < $lastModifiedMaster) { $labelClass = 'badge-warning'; - $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') . '
'; + $masterInfo = $saveHistory + ? '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') + : '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); } else { - $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC') . '
'; + $masterInfo = '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); } } } } - $tooltip = '' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '
' - . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); + $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
' + . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; $classes = 'badge ' . $labelClass; - $item->link = '' . $text . '' + $item->link = '' . $text . '' . ''; // Reorder the array, so the master item gets to the first place diff --git a/administrator/components/com_contact/tmpl/contacts/default.php b/administrator/components/com_contact/tmpl/contacts/default.php index 5bbdc30e21672..364e48504f337 100644 --- a/administrator/components/com_contact/tmpl/contacts/default.php +++ b/administrator/components/com_contact/tmpl/contacts/default.php @@ -78,7 +78,7 @@ - + @@ -165,7 +165,7 @@ access_level; ?> - + association) : ?> id); ?> diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index f7e8c9f3f132c..d63cf0cf3ba2c 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -11,6 +11,7 @@ defined('_JEXEC') or die; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Associations; @@ -42,6 +43,10 @@ public function association($articleid) // Defaults $html = ''; $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $masterInfo = ''; + + // Check if versions are enabled + $saveHistory = ComponentHelper::getParams('com_content')->get('save_history', 0); // Get the associations if ($associations = Associations::getAssociations('com_content', '#__content', 'com_content.item', $articleid)) @@ -103,10 +108,6 @@ public function association($articleid) foreach ($items as $key => &$item) { $labelClass = 'badge-success'; - $languageTitle = $item->language_title; - $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; - $title = $item->title; - $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); if ($globalMasterLanguage) { @@ -128,7 +129,7 @@ public function association($articleid) if ($key === $masterId) { $labelClass .= ' master-item'; - $languageTitle = $item->language_title . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); + $masterInfo = '

' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); } else { @@ -141,21 +142,25 @@ public function association($articleid) if ($associatedModifiedMaster < $lastModifiedMaster) { $labelClass = 'badge-warning'; - $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') . '
'; + $masterInfo = $saveHistory + ? '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') + : '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); } else { - $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC') . '
'; + $masterInfo = '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); } } } } $classes = 'badge ' . $labelClass; - $tooltip = '' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '
' - . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); + $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; + $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
' + . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; + $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); - $item->link = '' . $text . '' + $item->link = '' . $text . '' . ''; // Reorder the array, so the master item gets to the first place diff --git a/administrator/components/com_content/tmpl/articles/default.php b/administrator/components/com_content/tmpl/articles/default.php index 8d0e1386c44d6..b78986e9320ea 100644 --- a/administrator/components/com_content/tmpl/articles/default.php +++ b/administrator/components/com_content/tmpl/articles/default.php @@ -127,7 +127,7 @@ - + @@ -334,7 +334,7 @@ escape($item->access_level); ?> - + association) : ?> id); ?> diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index f165c4ad1df36..740054794916d 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -11,6 +11,7 @@ defined('_JEXEC') or die; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Text; @@ -39,6 +40,10 @@ public function association($newsfeedid) // Defaults $html = ''; $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $masterInfo = ''; + + // Check if versions are enabled + $saveHistory = ComponentHelper::getParams('com_newsfeeds')->get('save_history', 0); // Get the associations if ($associations = Associations::getAssociations('com_newsfeeds', '#__newsfeeds', 'com_newsfeeds.item', $newsfeedid)) @@ -80,7 +85,7 @@ public function association($newsfeedid) if ($globalMasterLanguage) { - // Check whether the current article is written in the global master language + // Check whether the current newsfeed is written in the global master language $masterElement = (array_key_exists($newsfeedid, $items) && ($items[$newsfeedid]->lang_code === $globalMasterLanguage)) ? true @@ -99,10 +104,6 @@ public function association($newsfeedid) foreach ($items as $key => &$item) { $labelClass = 'badge-success'; - $languageTitle = $item->language_title; - $text = strtoupper($item->lang_sef); - $title = $item->title; - $url = Route::_('index.php?option=com_newsfeeds&task=newsfeed.edit&id=' . (int) $item->id); if ($globalMasterLanguage) { @@ -123,7 +124,7 @@ public function association($newsfeedid) if ($key === $masterId) { $labelClass .= ' master-item'; - $languageTitle = $item->language_title . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); + $masterInfo = '

' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); } else { @@ -136,21 +137,25 @@ public function association($newsfeedid) if ($associatedModifiedMaster < $lastModifiedMaster) { $labelClass = 'badge-warning'; - $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') . '
'; + $masterInfo = $saveHistory + ? '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') + : '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); } else { - $title .= '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC') . '
'; + $masterInfo = '

' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); } } } } $classes = 'badge ' . $labelClass; - $tooltip = '' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '
' - . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); + $text = strtoupper($item->lang_sef); + $url = Route::_('index.php?option=com_newsfeeds&task=newsfeed.edit&id=' . (int) $item->id); + $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
' + . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; - $item->link = '' . $text . '' + $item->link = '' . $text . '' . ''; // Reorder the array, so the master item gets to the first place diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index d53242d0bc015..d708b259ef743 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -28,6 +28,7 @@ COM_ASSOCIATIONS_HEADING_ASSOCIATION="Associations" COM_ASSOCIATIONS_HEADING_MENUTYPE="Menu" COM_ASSOCIATIONS_HEADING_MENUTYPE_ASC="Menu ascending" COM_ASSOCIATIONS_HEADING_MENUTYPE_DESC="Menu descending" +COM_ASSOCIATIONS_HEADING_NO_ASSOCIATION="Not Associated" COM_ASSOCIATIONS_ITEMS="Items" COM_ASSOCIATIONS_NO_ASSOCIATION="There is no association for this language" COM_ASSOCIATIONS_NOTICE_NO_SELECTORS="Please select an Item Type and a reference language to view the associations." @@ -52,5 +53,6 @@ COM_ASSOCIATIONS_TITLE="Associations" COM_ASSOCIATIONS_TITLE_EDIT="Multilingual Associations: Edit Associations (%1s > %2s)" COM_ASSOCIATIONS_TITLE_LIST="Multilingual Associations (%1s > %2s)" COM_ASSOCIATIONS_TITLE_LIST_SELECT="Multilingual Associations: Select Item Type and Language" +COM_ASSOCIATIONS_UPDATE_ASSOCIATION="Update Association" COM_ASSOCIATIONS_XML_DESCRIPTION="Improved multilingual content management component" COM_ASSOCIATIONS_YOU_ARE_NOT_ALLOWED_TO_CHECKIN_THIS_ITEM="You can't check in this item" diff --git a/administrator/language/en-GB/en-GB.ini b/administrator/language/en-GB/en-GB.ini index 1298467ee5ede..4c91a7af5db79 100644 --- a/administrator/language/en-GB/en-GB.ini +++ b/administrator/language/en-GB/en-GB.ini @@ -280,7 +280,7 @@ JGLOBAL_ARTICLE_ORDER_LABEL="Article Order" JGLOBAL_ARTICLES="Articles" JGLOBAL_ASSOC_NOT_POSSIBLE="To define associations, please make sure the item language is not set to 'All'." JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE="Master" -JGLOBAL_ASSOCIATIONS_MASTER_ITEM="This is the master item" +JGLOBAL_ASSOCIATIONS_MASTER_ITEM="The master language" JGLOBAL_ASSOCIATIONS_NEW_ITEM_WARNING="To create associations, first save the item." JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON="Propagate" JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED="Failed propagating associations. You may have to select or create them manually." @@ -289,6 +289,7 @@ JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE="No associations exist to propagate. JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME="Associations have been set for: %s" JGLOBAL_ASSOCIATIONS_PROPAGATE_TIP="Propagates this item's existing associations." JGLOBAL_ASSOCIATIONS_RESET_WARNING="The language has been changed. If you save this item again it will reset the available associations. If this was not intended, close the item." +JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC="This item might be outdated with the master article." JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC="There is no association for the master language." JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC="This item is outdated with the master item." JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC="This item is up-to-date with the master item." diff --git a/administrator/templates/atum/scss/template.scss b/administrator/templates/atum/scss/template.scss index 9ab3a3992d71a..c9806d33f3b86 100644 --- a/administrator/templates/atum/scss/template.scss +++ b/administrator/templates/atum/scss/template.scss @@ -104,7 +104,6 @@ // Multilingual associations specific .item-associations { padding: 0; - position: relative; margin-bottom: 0; li, ul { @@ -113,13 +112,24 @@ padding: 0; } + &.master { + text-align: center; + + div[role="tooltip"] { + text-align: left; + } + } + hr { margin-top: 0.2rem; margin-bottom: 0.2rem; } - .master-language > a { - border-radius: 0; + .master-language { + + & > a { + border-radius: 0; + } } } diff --git a/build/media_source/com_associations/js/admin-compare-master.es6.js b/build/media_source/com_associations/js/admin-compare-master.es6.js index 950b0eae6b86b..737f16188c3f2 100644 --- a/build/media_source/com_associations/js/admin-compare-master.es6.js +++ b/build/media_source/com_associations/js/admin-compare-master.es6.js @@ -30,7 +30,6 @@ }); display.appendChild(fragment); - console.log(display); }; const onBoot = () => { diff --git a/build/media_source/com_associations/js/sidebysideupdate.es6.js b/build/media_source/com_associations/js/sidebysideupdate.es6.js index 75f910a4a9f4c..370546810a901 100644 --- a/build/media_source/com_associations/js/sidebysideupdate.es6.js +++ b/build/media_source/com_associations/js/sidebysideupdate.es6.js @@ -57,6 +57,9 @@ Joomla = window.Joomla || {}; // Update language field with the selected language and then disable it. target.querySelector('#jform_language').setAttribute('disabled', ''); + // Remove modal buttons on the reference + target.querySelector('#associations').querySelectorAll('.btn').forEach(e => e.parentNode.removeChild(e)); + // Iframe load finished, hide Joomla loading layer. Joomla.loadingLayer('hide'); } diff --git a/layouts/joomla/content/associations.php b/layouts/joomla/content/associations.php index ff8f2c3d0695d..c03e7c80aff15 100644 --- a/layouts/joomla/content/associations.php +++ b/layouts/joomla/content/associations.php @@ -12,27 +12,28 @@ $items = $displayData; if (!empty($items)) : ?> -
    -
  • - link; ?> -
    -
      - $item) : ?> - -
    • - link; ?> -
    • - - -
    -
  • - - $item) : ?> -
  • - link; ?> +
      +
    • + link; ?> +
      +
        + $item) : ?> + +
      • + link; ?> +
      • + + +
    • - + +
        + $item) : ?> +
      • + link; ?> +
      • +
      From e22457d4d0e8b0704632d51ff1e9a0ffdc0d7bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 1 Jul 2019 14:49:57 +0200 Subject: [PATCH 34/98] adjust code style and rename variables and function --- .../Helper/AssociationsHelper.php | 34 +++++++++--------- .../Helper/MasterAssociationsHelper.php | 36 +++++++++---------- .../View/Association/HtmlView.php | 35 +++++++++--------- .../tmpl/associations/default.php | 12 +++---- .../com_categories/Model/CategoryModel.php | 9 +++-- .../Service/HTML/AdministratorService.php | 10 +++--- .../tmpl/categories/default.php | 18 +++++----- .../Service/HTML/AdministratorService.php | 12 +++---- .../Service/HTML/AdministratorService.php | 8 ++--- .../components/com_menus/Model/ItemModel.php | 6 ++-- .../Service/HTML/AdministratorService.php | 10 +++--- .../language/en-GB/en-GB.com_associations.ini | 2 +- installation/src/Model/LanguagesModel.php | 4 +-- libraries/src/MVC/Model/AdminModel.php | 9 +++-- 14 files changed, 101 insertions(+), 104 deletions(-) diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 10ab578867d63..7ae32b4122671 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -234,7 +234,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId if ($items) { // Get master dates of each item of an association - $assocParams = MasterAssociationsHelper::getAssociationsParams($items, $context); + $assocMasterDates = MasterAssociationsHelper::getMasterDates($items, $context); $masterId = $items[$globalMasterLanguage]['id'] ?? null; } @@ -249,16 +249,16 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId // Create associated items list. foreach ($languages as $langCode => $language) { - $update = false; + $update = false; $masterInfo = ''; if(!$globalMasterLanguage) { - // Don't do for the reference language + // Don't do for the reference language if ($langCode == $itemLanguage) - { - continue; - } + { + continue; + } // Don't show languages with associations, if we don't want to show them. if ($assocLanguages && isset($items[$langCode])) @@ -332,7 +332,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId // Settings for the master language if ($globalMasterLanguage === $langCode) { - $labelClass .= ' master-item'; + $labelClass .= ' master-item'; $additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : ''; $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); @@ -354,10 +354,10 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $target = $globalMasterLanguage . ':0:add'; } - if (array_key_exists($items[$langCode]['id'], $assocParams) && array_key_exists($masterId, $assocParams)) + if (array_key_exists($items[$langCode]['id'], $assocMasterDates) && array_key_exists($masterId, $assocMasterDates)) { - $associatedModifiedMaster = $assocParams[$items[$langCode]['id']]; - $lastModifiedMaster = $assocParams[$masterId]; + $associatedModifiedMaster = $assocMasterDates[$items[$langCode]['id']]; + $lastModifiedMaster = $assocMasterDates[$masterId]; if ($associatedModifiedMaster < $lastModifiedMaster) { @@ -417,19 +417,19 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $items[$langCode] = array(); - $title = Text::_('COM_ASSOCIATIONS_NO_ASSOCIATION'); - $additional = $addLink ? Text::_('COM_ASSOCIATIONS_ADD_NEW_ASSOCIATION') : ''; - $labelClass = 'badge-secondary'; - $target = $langCode . ':0:add'; - $allow = $canCreate; + $title = Text::_('COM_ASSOCIATIONS_NO_ASSOCIATION'); + $additional = $addLink ? Text::_('COM_ASSOCIATIONS_ADD_NEW_ASSOCIATION') : ''; + $labelClass = 'badge-secondary'; + $target = $langCode . ':0:add'; + $allow = $canCreate; if ($globalMasterLanguage) { if ($globalMasterLanguage === $langCode) { - $labelClass .= ' master-item'; + $labelClass .= ' master-item'; $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); - $target = ''; + $target = ''; } else { diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 15109740645a5..1cec19cc3df9a 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -43,13 +43,13 @@ public static function addNotAssociatedMasterLink($globalMasterLanguage) $db->setQuery($query); $globalMasterLanguageInfos = $db->loadAssoc(); - $classes = 'hasPopover badge badge-secondary'; + $classes = 'hasPopover badge badge-secondary'; $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); - $text = $globalMasterLanguageInfos['sef'] + $text = $globalMasterLanguageInfos['sef'] ? strtoupper($globalMasterLanguageInfos['sef']) : 'XX'; - $title = Text::_('JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC'); - $url = ''; + $title = Text::_('JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC'); + $url = ''; $tooltip = '' . htmlspecialchars( $globalMasterLanguageInfos['title'], ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . $masterInfo; @@ -69,7 +69,7 @@ public static function addNotAssociatedMasterLink($globalMasterLanguage) * @return array association with master dates * */ - public static function getAssociationsParams($associations, $context) + public static function getMasterDates($associations, $context) { $db = Factory::getDbo(); @@ -79,17 +79,17 @@ public static function getAssociationsParams($associations, $context) { $id = $id['id']; } + $query = $db->getQuery(true) ->select($db->quoteName('assocParams')) ->from($db->quoteName('#__associations')) ->where($db->quoteName('id') . ' = ' . $db->quote($id)) ->where($db->quoteName('context') . ' = ' . $db->quote($context)); $db->setQuery($query); - $param = $db->loadResult(); - $assocParams[$id] = $param; + $masterDates[$id] = $db->loadResult();; } - return $assocParams; + return $masterDates; } /** @@ -104,42 +104,42 @@ public static function getAssociationsParams($associations, $context) * * @return array master id and master dates for an associated item */ - public static function setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $old_key) { + public static function setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $old_key) { if ($masterId) { // For the master item if ($masterId === $id) { - $parentId = 0; + $masterIdValue = 0; // set always the last modified date - $parentModified = $masterModified ?? null; + $masterDateValue = $masterModified ?? null; } // For the children else { - $parentId = $masterId; + $masterIdValue = $masterId; // if modified date isn't set to the child item set it with current modified date from master - $parentModified = empty($associationsParams[$id]) + $masterDateValue = empty($assocMasterDates[$id]) ? $masterModified - : $associationsParams[$id]; + : $assocMasterDates[$id]; if (!$old_key && ($dataId === $id)) { // Add modified date from master to new associated item - $parentModified = $masterModified ?? null; + $masterDateValue = $masterModified ?? null; } } } // default values when there is no associated master item else { - $parentId = -1; - $parentModified = null; + $masterIdValue = -1; + $masterDateValue = null; } - return [$parentId, $parentModified]; + return [$masterIdValue, $masterDateValue]; } /** diff --git a/administrator/components/com_associations/View/Association/HtmlView.php b/administrator/components/com_associations/View/Association/HtmlView.php index 35b9098d0e0f5..c62098a5eb543 100644 --- a/administrator/components/com_associations/View/Association/HtmlView.php +++ b/administrator/components/com_associations/View/Association/HtmlView.php @@ -244,27 +244,26 @@ protected function addToolbar() ); } else + { + $toolbar->appendButton( + 'Custom', '', + 'reference' + ); + + $toolbar->appendButton( + 'Custom', '', 'target' + ); + + if ($this->typeName === 'category' || $this->extensionName === 'com_menus' || $this->save2copy === true) { - $toolbar->appendButton( - 'Custom', '', - 'reference' - ); - - $toolbar->appendButton( - 'Custom', '', 'target' - ); - - if ($this->typeName === 'category' || $this->extensionName === 'com_menus' || $this->save2copy === true) - { - ToolbarHelper::custom('copy', 'copy.png', '', 'COM_ASSOCIATIONS_COPY_REFERENCE', false); - } + ToolbarHelper::custom('copy', 'copy.png', '', 'COM_ASSOCIATIONS_COPY_REFERENCE', false); + } } - ToolbarHelper::cancel('association.cancel', 'JTOOLBAR_CLOSE'); ToolbarHelper::help('JHELP_COMPONENTS_ASSOCIATIONS_EDIT'); } diff --git a/administrator/components/com_associations/tmpl/associations/default.php b/administrator/components/com_associations/tmpl/associations/default.php index 89ffa6464cec7..3194a3430ed0b 100644 --- a/administrator/components/com_associations/tmpl/associations/default.php +++ b/administrator/components/com_associations/tmpl/associations/default.php @@ -19,11 +19,11 @@ HTMLHelper::_('behavior.multiselect'); -$listOrder = $this->escape($this->state->get('list.ordering')); -$listDirn = $this->escape($this->state->get('list.direction')); +$listOrder = $this->escape($this->state->get('list.ordering')); +$listDirn = $this->escape($this->state->get('list.direction')); $canManageCheckin = Factory::getUser()->authorise('core.manage', 'com_checkin'); $globalMasterLanguage = Associations::getGlobalMasterLanguage(); -$assocState = $this->escape($this->state->get('assocstate')); +$assocState = $this->escape($this->state->get('assocstate')); $iconStates = array( -2 => 'icon-trash', @@ -63,8 +63,8 @@ - - + + @@ -141,7 +141,7 @@ extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout, true); ?> - + typeFields['menutype'])) : ?> diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index 70937197eef53..4b9141da479f2 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -632,7 +632,7 @@ public function save($data) } // Get association params before they get deleted - $associationsParams = MasterAssociationsHelper::getAssociationsParams($associations, $this->associationsContext); + $associationsParams = MasterAssociationsHelper::getMasterDates($associations, $this->associationsContext); // Get associationskey for edited item $db = $this->getDbo(); @@ -696,11 +696,10 @@ public function save($data) foreach ($associations as $id) { - $masterValues = MasterAssociationsHelper::setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $oldKey); - $parentId = $masterValues[0]; - $parentModified = $masterValues[1]; + $masterIdAndDateValues = MasterAssociationsHelper::setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $oldKey); - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($parentId) . ',' . $db->quote($parentModified)); + $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' + . $db->quote($masterIdAndDateValues[0]) . ',' . $db->quote($masterIdAndDateValues[1])); } $db->setQuery($query); diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index 0362235499f25..57699ed4fd3dd 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -91,7 +91,7 @@ public function association($catid, $extension = 'com_content') ? $associations[$globalMasterLanguage] : ''; - $assocParams = MasterAssociationsHelper::getAssociationsParams($associations, 'com_categories.item'); + $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_categories.item'); } if ($items) @@ -129,11 +129,11 @@ public function association($catid, $extension = 'com_content') else { // get association state of child when a master exists - if ($masterId && array_key_exists($key, $assocParams) - && array_key_exists($masterId, $assocParams)) + if ($masterId && array_key_exists($key, $assocMasterDates) + && array_key_exists($masterId, $assocMasterDates)) { - $associatedModifiedMaster = $assocParams[$key]; - $lastModifiedMaster = $assocParams[$masterId]; + $associatedModifiedMaster = $assocMasterDates[$key]; + $lastModifiedMaster = $assocMasterDates[$masterId]; if ($associatedModifiedMaster < $lastModifiedMaster) { diff --git a/administrator/components/com_categories/tmpl/categories/default.php b/administrator/components/com_categories/tmpl/categories/default.php index 51526bb84717f..8086e8eb88ef6 100644 --- a/administrator/components/com_categories/tmpl/categories/default.php +++ b/administrator/components/com_categories/tmpl/categories/default.php @@ -21,15 +21,15 @@ HTMLHelper::_('behavior.multiselect'); -$user = Factory::getUser(); -$userId = $user->get('id'); -$extension = $this->escape($this->state->get('filter.extension')); -$listOrder = $this->escape($this->state->get('list.ordering')); -$listDirn = $this->escape($this->state->get('list.direction')); -$saveOrder = ($listOrder == 'a.lft' && strtolower($listDirn) == 'asc'); -$parts = explode('.', $extension, 2); -$component = $parts[0]; -$section = null; +$user = Factory::getUser(); +$userId = $user->get('id'); +$extension = $this->escape($this->state->get('filter.extension')); +$listOrder = $this->escape($this->state->get('list.ordering')); +$listDirn = $this->escape($this->state->get('list.direction')); +$saveOrder = ($listOrder == 'a.lft' && strtolower($listDirn) == 'asc'); +$parts = explode('.', $extension, 2); +$component = $parts[0]; +$section = null; $masterAlign = Associations::getGlobalMasterLanguage() ? 'text-center ' : ''; if (count($parts) > 1) diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index 2d71e91e83a42..eb824f4d1b083 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -98,7 +98,7 @@ public function association($contactid) ? $associations[$globalMasterLanguage] : ''; - $assocParams = MasterAssociationsHelper::getAssociationsParams($associations, 'com_contact.item'); + $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_contact.item'); } if ($items) @@ -128,17 +128,17 @@ public function association($contactid) if ($key === $masterId) { - $labelClass .= ' master-item'; + $labelClass .= ' master-item'; $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); - $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); + $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); } else { // get association state of child - if ($masterId && array_key_exists($key, $assocParams) && array_key_exists($masterId, $assocParams)) + if ($masterId && array_key_exists($key, $assocMasterDates) && array_key_exists($masterId, $assocMasterDates)) { - $associatedModifiedMaster = $assocParams[$key]; - $lastModifiedMaster = $assocParams[$masterId]; + $associatedModifiedMaster = $assocMasterDates[$key]; + $lastModifiedMaster = $assocMasterDates[$masterId]; if ($associatedModifiedMaster < $lastModifiedMaster) { diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index d63cf0cf3ba2c..3fff01d624f78 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -100,7 +100,7 @@ public function association($articleid) ? $associations[$globalMasterLanguage] : ''; - $assocParams = MasterAssociationsHelper::getAssociationsParams($associations, 'com_content.item'); + $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_content.item'); } if ($items) @@ -134,10 +134,10 @@ public function association($articleid) else { // get association state of child - if ($masterId && array_key_exists($key, $assocParams) && array_key_exists($masterId, $assocParams)) + if ($masterId && array_key_exists($key, $assocMasterDates) && array_key_exists($masterId, $assocMasterDates)) { - $associatedModifiedMaster = $assocParams[$key]; - $lastModifiedMaster = $assocParams[$masterId]; + $associatedModifiedMaster = $assocMasterDates[$key]; + $lastModifiedMaster = $assocMasterDates[$masterId]; if ($associatedModifiedMaster < $lastModifiedMaster) { diff --git a/administrator/components/com_menus/Model/ItemModel.php b/administrator/components/com_menus/Model/ItemModel.php index efe2432abaae6..901303500c6b3 100644 --- a/administrator/components/com_menus/Model/ItemModel.php +++ b/administrator/components/com_menus/Model/ItemModel.php @@ -1581,7 +1581,7 @@ public function save($data) { // If there is an association item with the globalMasterLanguage, then get his id $globalMasterLanguage = Associations::getGlobalMasterLanguage(); - $masterID = $associations[$globalMasterLanguage] ?? ''; + $masterId = $associations[$globalMasterLanguage] ?? ''; // Adding new association for these items $key = md5(json_encode($associations)); @@ -1592,8 +1592,8 @@ public function save($data) { // If there is no master item in this association, then reset the parent_id to -1 // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. - $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($parentId) . ',' . $db->quote('')); + $masterIdValue = $masterId ? ($masterId === $id ? 0 : $masterId) : -1; + $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($masterIdValue) . ',' . $db->quote(null)); } $db->setQuery($query); diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index 740054794916d..a6b7e0a920a39 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -96,14 +96,14 @@ public function association($newsfeedid) ? $associations[$globalMasterLanguage] : ''; - $assocParams = MasterAssociationsHelper::getAssociationsParams($associations, 'com_newsfeeds.item'); + $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_newsfeeds.item'); } if ($items) { foreach ($items as $key => &$item) { - $labelClass = 'badge-success'; + $labelClass = 'badge-success'; if ($globalMasterLanguage) { @@ -129,10 +129,10 @@ public function association($newsfeedid) else { // get association state of child - if ($masterId && array_key_exists($key, $assocParams) && array_key_exists($masterId, $assocParams)) + if ($masterId && array_key_exists($key, $assocMasterDates) && array_key_exists($masterId, $assocMasterDates)) { - $associatedModifiedMaster = $assocParams[$key]; - $lastModifiedMaster = $assocParams[$masterId]; + $associatedModifiedMaster = $assocMasterDates[$key]; + $lastModifiedMaster = $assocMasterDates[$masterId]; if ($associatedModifiedMaster < $lastModifiedMaster) { diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index d708b259ef743..27c2ee9e897fb 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -53,6 +53,6 @@ COM_ASSOCIATIONS_TITLE="Associations" COM_ASSOCIATIONS_TITLE_EDIT="Multilingual Associations: Edit Associations (%1s > %2s)" COM_ASSOCIATIONS_TITLE_LIST="Multilingual Associations (%1s > %2s)" COM_ASSOCIATIONS_TITLE_LIST_SELECT="Multilingual Associations: Select Item Type and Language" -COM_ASSOCIATIONS_UPDATE_ASSOCIATION="Update Association" +COM_ASSOCIATIONS_UPDATE_ASSOCIATION="Update association" COM_ASSOCIATIONS_XML_DESCRIPTION="Improved multilingual content management component" COM_ASSOCIATIONS_YOU_ARE_NOT_ALLOWED_TO_CHECKIN_THIS_ITEM="You can't check in this item" diff --git a/installation/src/Model/LanguagesModel.php b/installation/src/Model/LanguagesModel.php index 28f2a74fc20b4..32f95ca95f329 100644 --- a/installation/src/Model/LanguagesModel.php +++ b/installation/src/Model/LanguagesModel.php @@ -1421,8 +1421,8 @@ public function addAssociations($groupedAssociations) { // If there is no master item in this association, then reset the parent_id to -1 // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. - $parentId = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; - $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($parentId) . ',' . $db->quote('')); + $masterIdValue = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; + $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($masterIdValue) . ',' . $db->quote('')); } $db->setQuery($query); diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 61d807a3fbc04..235a9328ffafc 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -1323,7 +1323,7 @@ public function save($data) // Get association params before they get deleted if($associations) { - $associationsParams = MasterAssociationsHelper::getAssociationsParams($associations, $this->associationsContext); + $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, $this->associationsContext); } // Get associationskey for edited item @@ -1377,11 +1377,10 @@ public function save($data) foreach ($associations as $id) { - $masterValues = MasterAssociationsHelper::setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $old_key); - $parentId = $masterValues[0]; - $parentModified = $masterValues[1]; + $masterIdAndDateValues = MasterAssociationsHelper::setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $old_key); - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($parentId) . ',' . $db->quote($parentModified)); + $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) + . ',' . $db->quote($masterIdAndDateValues[0]) . ',' . $db->quote($masterIdAndDateValues[1])); } $db->setQuery($query); From fc95e695470ca664c4a5e0fa21b318adb3e9cc25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 1 Jul 2019 16:52:20 +0200 Subject: [PATCH 35/98] open item as target if it is a child language When opening the association edit view via the associations-button from an item, then open this item as target, if an associated master item exists, and the master item as reference. --- libraries/src/MVC/Model/AdminModel.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 235a9328ffafc..3cbbe14e7d9ca 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -1663,6 +1663,20 @@ public function editAssociations($data) } } + $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $isMaster = $data['language'] === $globalMasterLanguage; + + // If a global Master Language is set and the current item is a child item, then open the master item as reference and the child as target + if ($globalMasterLanguage && !$isMaster) + { + // if there is an associated master item change reference id. + if($data['associations'][$globalMasterLanguage]) + { + $id = $data['associations'][$globalMasterLanguage]; + $target = '&target=' . $data['language'] . '%3A' . $data['id'] . '%3Aedit'; + } + } + $app->redirect( Route::_( 'index.php?option=com_associations&view=association&layout=edit&itemtype=' . $this->typeAlias From 550db64d0b725efd13cd18d3f1347da3cbc018f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 1 Jul 2019 17:00:26 +0200 Subject: [PATCH 36/98] don't display other target languages if master language is one of them In Association Edit View: When a child item is the current reference then the target has to be the master language. Other child languages has no direct relationship to this child, so it makes no sense to display them in the language filter. --- .../Field/ItemlanguageField.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/administrator/components/com_associations/Field/ItemlanguageField.php b/administrator/components/com_associations/Field/ItemlanguageField.php index 3f23450b9c8b9..de884af2bde7f 100644 --- a/administrator/components/com_associations/Field/ItemlanguageField.php +++ b/administrator/components/com_associations/Field/ItemlanguageField.php @@ -13,7 +13,9 @@ use Joomla\CMS\Factory; use Joomla\CMS\Form\Field\ListField; +use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\LanguageHelper; +use Joomla\CMS\Language\Text; use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper; use Joomla\Utilities\ArrayHelper; @@ -62,6 +64,10 @@ protected function getOptions() // Gets existing languages. $existingLanguages = LanguageHelper::getContentLanguages(array(0, 1)); + // Get global master language and check if reference is a master item. + $globalMasterLang = Associations::getGlobalMasterLanguage(); + $refIsMaster = $referenceLang === $globalMasterLang; + $options = array(); // Each option has the format "|", example: "en-GB|1" @@ -73,9 +79,23 @@ protected function getOptions() continue; } + if ($globalMasterLang && !$refIsMaster) + { + // If reference is a child then display just the master language + if ($language->lang_code !== $globalMasterLang) + { + continue; + } + } + $options[$langCode] = new \stdClass; $options[$langCode]->text = $language->title; + if ($globalMasterLang && ($language->lang_code === $globalMasterLang)) + { + $options[$langCode]->text .= ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); + } + // If association exists in this language. if (isset($associations[$language->lang_code])) { From eaf8ce2fee47a98e5f0e06d66d37496fe5ce76f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 1 Jul 2019 20:31:25 +0200 Subject: [PATCH 37/98] improve code style and new function for masterInfo in ListViews The same code is now moved to a function where the class name and the info text of the association status are set. The code style improvements include changes to variable names, the position of variables, improving comments, and text alignments. --- .../Field/ContentmasterlanguageField.php | 8 +- .../Helper/AssociationsHelper.php | 97 ++++++++------- .../Helper/MasterAssociationsHelper.php | 117 +++++++++++++----- .../Model/AssociationsModel.php | 36 +++--- .../View/Associations/HtmlView.php | 9 +- .../layouts/joomla/searchtools/default.php | 6 +- .../tmpl/associations/default.php | 14 +-- .../com_categories/Model/CategoryModel.php | 9 +- .../Service/HTML/AdministratorService.php | 98 ++++++--------- .../Service/HTML/AdministratorService.php | 82 ++++-------- .../Service/HTML/AdministratorService.php | 74 ++++------- .../components/com_menus/Model/ItemModel.php | 10 +- .../com_menus/Service/HTML/Menus.php | 27 ++-- .../Service/HTML/AdministratorService.php | 70 +++-------- .../en-GB/en-GB.plg_system_languagefilter.ini | 2 +- installation/src/Model/LanguagesModel.php | 12 +- libraries/src/Language/Associations.php | 10 +- libraries/src/MVC/Model/AdminModel.php | 21 ++-- .../system/languagefilter/languagefilter.php | 68 +++++----- 19 files changed, 349 insertions(+), 421 deletions(-) diff --git a/administrator/components/com_associations/Field/ContentmasterlanguageField.php b/administrator/components/com_associations/Field/ContentmasterlanguageField.php index dfa7065ab9812..daa598dc5cd1a 100644 --- a/administrator/components/com_associations/Field/ContentmasterlanguageField.php +++ b/administrator/components/com_associations/Field/ContentmasterlanguageField.php @@ -44,7 +44,7 @@ class ContentmasterlanguageField extends ContentlanguageField */ public function getOptions() { - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $globalMasterLang = Associations::getGlobalMasterLanguage(); $contentLanguages = LanguageHelper::getContentLanguages(array(0, 1)); $options = array(); @@ -54,11 +54,9 @@ public function getOptions() foreach ($contentLanguages as $langCode) { // Add information to the language if it is the global master language - if ($langCode->lang_code == $globalMasterLanguage) + if ($langCode->lang_code == $globalMasterLang) { - $options[] = HTMLHelper::_('select.option', $langCode->lang_code, $langCode->title . ' - ' - . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE') - ); + $options[] = HTMLHelper::_('select.option', $langCode->lang_code, $langCode->title . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE')); } else { diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 7ae32b4122671..ba0375b8b2c4d 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -213,7 +213,7 @@ private static function getExtensionRealName($extensionName) * @param string $itemLanguage Item language code. * @param boolean $addLink True for adding edit links. False for just text. * @param boolean $assocLanguages True for showing non associated content languages. False only languages with associations. - * @param string $assocState The filter association state, enabled when a global master language is used + * @param string $assocState The filter association state, enabled when a global master language is used. * * @return string The language HTML * @@ -221,22 +221,8 @@ private static function getExtensionRealName($extensionName) */ public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true, $assocLanguages = true, $assocState = 'all') { - // Get the global master language, empty if not used - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); - - // Check if versions are enabled - $saveHistory = ComponentHelper::getParams($extensionName)->get('save_history', 0); - // Get the associations list for this item. $items = self::getAssociationList($extensionName, $typeName, $itemId); - $context = ($typeName === 'category') ? 'com_categories.item' : $extensionName . '.item'; - - if ($items) - { - // Get master dates of each item of an association - $assocMasterDates = MasterAssociationsHelper::getMasterDates($items, $context); - $masterId = $items[$globalMasterLanguage]['id'] ?? null; - } $titleFieldName = self::getTypeFieldName($extensionName, $typeName, 'title'); @@ -246,15 +232,29 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $canEditReference = self::allowEdit($extensionName, $typeName, $itemId); $canCreate = self::allowAdd($extensionName, $typeName); + // Get the global master language, empty if not used + $globalMasterLang = Associations::getGlobalMasterLanguage(); + // Check if versions are enabled + $saveHistory = ComponentHelper::getParams($extensionName)->get('save_history', 0); + $context = ($typeName === 'category') ? 'com_categories.item' : $extensionName . '.item'; + + if ($items) + { + // Get master dates of each item of an association and the master id. + $assocMasterDates = MasterAssociationsHelper::getMasterDates($items, $context); + $masterId = $items[$globalMasterLang]['id'] ?? null; + } + // Create associated items list. foreach ($languages as $langCode => $language) { + // Defaults $update = false; $masterInfo = ''; - if(!$globalMasterLanguage) + if(!$globalMasterLang) { - // Don't do for the reference language + // Don't do for the reference language. if ($langCode == $itemLanguage) { continue; @@ -274,17 +274,17 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId } } - // Get html parameters for associated items + // Get html parameters for associated items. if (isset($items[$langCode])) { - if ($globalMasterLanguage) + if ($globalMasterLang) { - // Don't display any other children to the child item - if (($langCode !== $globalMasterLanguage) && ($langCode !== $itemLanguage) && $itemLanguage !== $globalMasterLanguage) - { - unset($items[$langCode]); - continue; - } + // Don't display any other children to the child item. + if (($itemLanguage !== $globalMasterLang) && ($langCode !== $globalMasterLang) && ($langCode !== $itemLanguage)) + { + unset($items[$langCode]); + continue; + } } $title = $items[$langCode][$titleFieldName]; @@ -321,22 +321,24 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $additional = '' . Text::sprintf('COM_MENUS_MENU_SPRINTF', $menutype_title) . '
      '; } - $labelClass = 'badge-success'; - $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; - $allow = $canEditReference - && self::allowEdit($extensionName, $typeName, $items[$langCode]['id']) - && self::canCheckinItem($extensionName, $typeName, $items[$langCode]['id']); + $labelClass = 'badge-success'; + $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; + $allow = $canEditReference + && self::allowEdit($extensionName, $typeName, $items[$langCode]['id']) + && self::canCheckinItem($extensionName, $typeName, $items[$langCode]['id']); + + $masterInfoSpace = $additional && !$addLink ? '
      ' : '

      '; - if ($globalMasterLanguage) + if ($globalMasterLang) { // Settings for the master language - if ($globalMasterLanguage === $langCode) + if ($globalMasterLang === $langCode) { $labelClass .= ' master-item'; $additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : ''; - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); + $masterInfo = $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); - if ($globalMasterLanguage === $itemLanguage) + if ($globalMasterLang === $itemLanguage) { // Do not define any child target as there can be more than one $target = ''; @@ -351,7 +353,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId { // When there is no associated master item, set it to target if (!$masterId){ - $target = $globalMasterLanguage . ':0:add'; + $target = $globalMasterLang . ':0:add'; } if (array_key_exists($items[$langCode]['id'], $assocMasterDates) && array_key_exists($masterId, $assocMasterDates)) @@ -372,12 +374,12 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; $update = true; - // when versions are disabled than the modified date is used for the master item. + // When versions are disabled than the modified date is used for the master item. // That means that when no changes were made and the master item has been saved the modified date has been changed. // So the outdated state means in that case there might have been made changes and it is necessary to check manually and update the target. $masterInfo = $saveHistory - ? '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') - : '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); + ? $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') + : $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); } else { @@ -388,7 +390,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId } $additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : ''; - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); + $masterInfo = $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); // for item types that do not use modified date or versions like menu items if (!$associatedModifiedMaster) @@ -408,9 +410,9 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId else { // Don't display any other children to the child item - if ($globalMasterLanguage && ($itemLanguage != $globalMasterLanguage) + if ($globalMasterLang && ($itemLanguage != $globalMasterLang) && ($langCode != $itemLanguage) - && ($langCode != $globalMasterLanguage)) + && ($langCode != $globalMasterLang)) { continue; } @@ -423,12 +425,13 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $target = $langCode . ':0:add'; $allow = $canCreate; - if ($globalMasterLanguage) + if ($globalMasterLang) { - if ($globalMasterLanguage === $langCode) + if ($globalMasterLang === $langCode) { $labelClass .= ' master-item'; - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); + $masterInfoSpace = $addLink ? '

      ' : ''; + $masterInfo = $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); $target = ''; } else @@ -442,9 +445,9 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId } // Change target, when there is no association with the global master language for the child item - if ($globalMasterLanguage !== $itemLanguage) + if ($globalMasterLang !== $itemLanguage) { - $target = $globalMasterLanguage . ':0:add'; + $target = $globalMasterLang . ':0:add'; } } } @@ -472,7 +475,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId . '
      ' . $tooltip . '
      '; // Reorder the array, so the master item gets to the first place - if ($langCode === $globalMasterLanguage) + if ($langCode === $globalMasterLang) { $items = array('master' => $items[$langCode]) + $items; unset($items[$langCode]); diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 1cec19cc3df9a..5f414fcdfc4f4 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -28,45 +28,42 @@ class MasterAssociationsHelper extends ContentHelper /** * Method to create a link for a child item that has no master item * - * @param string $globalMasterLanguage The global master language + * @param string $globalMasterLang The global master language * - * @return string the link for the not associated master item + * @return string the link for the not associated master item */ - public static function addNotAssociatedMasterLink($globalMasterLanguage) + public static function addNotAssociatedMasterLink($globalMasterLang) { $db = Factory::getDbo(); $query = $db->getQuery(true) ->select('title, sef') ->from('#__languages') - ->where($db->quoteName('lang_code') . ' = ' - . $db->quote($globalMasterLanguage)); + ->where($db->quoteName('lang_code') . ' = ' . $db->quote($globalMasterLang)); $db->setQuery($query); - $globalMasterLanguageInfos = $db->loadAssoc(); + $globalMasterLangInfos = $db->loadAssoc(); $classes = 'hasPopover badge badge-secondary'; $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); - $text = $globalMasterLanguageInfos['sef'] - ? strtoupper($globalMasterLanguageInfos['sef']) - : 'XX'; + $text = $globalMasterLangInfos['sef'] ? strtoupper($globalMasterLangInfos['sef']) : 'XX'; $title = Text::_('JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC'); $url = ''; - $tooltip = '' . htmlspecialchars( $globalMasterLanguageInfos['title'], ENT_QUOTES, 'UTF-8') . '
      ' + $tooltip = '' . htmlspecialchars( $globalMasterLangInfos['title'], ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . $masterInfo; - $link = '' . $text . '' + $link = '' . $text . '' . ''; return $link; } /** - * Method to get master dates for each item of an association. + * Method to get master dates of each item of an association. * * @param array $associations the associations to be saved. * @param string $context the association context * - * @return array association with master dates + * @return array association with master dates * */ public static function getMasterDates($associations, $context) @@ -93,18 +90,18 @@ public static function getMasterDates($associations, $context) } /** - * Method to set master_id and master_date for an association that get to be saved + * Method to get master_id and master_date for an association going to be saved. * - * @param integer $id Item id - * @param integer $dataId Item id of an item that is going to be saved - * @param integer $masterId Id of the associated master item - * @param string $masterModified The latest modified date of the master - * @param array $assocMasterDates Masters modified date of an associated item - * @param string $old_key The old association key to check if it is a new association + * @param integer $id Item id + * @param integer $dataId Item id of an item that is going to be saved + * @param integer $masterId Id of the associated master item + * @param string $masterModified The latest modified date of the master + * @param array $assocMasterDates Masters modified date of an associated item + * @param string $old_key The old association key to check if it is a new association * - * @return array master id and master dates for an associated item + * @return array master id and master dates for an associated item */ - public static function setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $old_key) { + public static function getMasterValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $old_key) { if ($masterId) { @@ -115,12 +112,13 @@ public static function setMasterLanguageValues($id, $dataId, $masterId, $masterM // set always the last modified date $masterDateValue = $masterModified ?? null; } + // For the children else { $masterIdValue = $masterId; - // if modified date isn't set to the child item set it with current modified date from master + // If modified date isn't set to the child item, set current modified date from master. $masterDateValue = empty($assocMasterDates[$id]) ? $masterModified : $assocMasterDates[$id]; @@ -132,24 +130,24 @@ public static function setMasterLanguageValues($id, $dataId, $masterId, $masterM } } } - // default values when there is no associated master item else { - $masterIdValue = -1; + // Default values when there is no associated master item. + $masterIdValue = -1; $masterDateValue = null; } - return [$masterIdValue, $masterDateValue]; + return [(int) $masterIdValue, $masterDateValue]; } /** - * Get the latest modified date of an master item + * Method to get the latest modified date of an master item * - * @param integer $masterId Id of the associated master item - * @param string $tableName The name of the table. - * @param string $typeAlias Alias for the content type + * @param integer $masterId Id of the associated master item + * @param string $tableName The name of the table. + * @param string $typeAlias Alias for the content type * - * @return string The modified date of the master item + * @return string The modified date of the master item */ public static function getMasterModifiedDate($masterId, $tableName, $typeAlias) { @@ -192,4 +190,61 @@ public static function getMasterModifiedDate($masterId, $tableName, $typeAlias) return $masterModified ?? ''; } + + /** + * Method to set class name and information about the association state or the master item. + * + * @param integer $itemId Item id + * @param array $items The associated items for the item with the itemId + * @param integer $key The current key from $items that is currently going through the foreach loop. + * @param array $item The current value from $items that is currently going through the foreach loop. + * @param boolean $isMaster If the item with $itemId is a master item. + * @param integer $masterId Id of the associated master item. + * @param array $assocMasterDates Master Dates of each associated item. + * @param boolean $saveHistory If Versions are enabled or not. + * + * @return array the className and masterInfo for the association state + */ + public static function setMasterAndChildInfos($itemId, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory) + { + + $addClass = 'badge-success'; + $masterInfo = ''; + + // Don't display other children if the current item is a child of the master language. + if (($key !== $itemId) && ($globalMasterLang !== $item->lang_code) && !$isMaster) + { + unset($items[$key]); + } + + if ($key === $masterId) + { + $addClass .= ' master-item'; + $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); + } + else + { + // get association state of child when a master exists + if ($masterId && (array_key_exists($key, $assocMasterDates)) && (array_key_exists($masterId, $assocMasterDates))) + { + $associatedModifiedMaster = $assocMasterDates[$key]; + $lastModifiedMaster = $assocMasterDates[$masterId]; + + if ($associatedModifiedMaster < $lastModifiedMaster) + { + $addClass = 'badge-warning'; + $masterInfo = $saveHistory + ? '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') + : '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); + } + else + { + $addClass = 'badge-success'; + $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); + } + } + } + + return [$addClass, $masterInfo]; + } } diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index b7d912bf04d09..57a74aebc6138 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -83,9 +83,9 @@ protected function populateState($ordering = 'ordering', $direction = 'asc') $forcedItemType = $app->input->get('forcedItemType', '', 'string'); // Set language select box to default site language or if set to the master language as default. - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); - $defaultLanguage = !empty($globalMasterLanguage) ? $globalMasterLanguage : ComponentHelper::getParams('com_languages')->get('site'); - $defaultItemType = 'com_content.article'; + $globalMasterLang = Associations::getGlobalMasterLanguage(); + $defaultLanguage = $globalMasterLang ?? ComponentHelper::getParams('com_languages')->get('site'); + $defaultItemType = 'com_content.article'; // Adjust the context to support modal layouts. if ($layout = $app->input->get('layout')) @@ -241,9 +241,7 @@ protected function getListQuery() $query->select($db->quoteName($fields['language'], 'language')) ->select($db->quoteName('l.title', 'language_title')) ->select($db->quoteName('l.image', 'language_image')) - ->join('LEFT', $db->quoteName('#__languages', 'l') - . ' ON ' . $db->quoteName('l.lang_code') . ' = ' . $db->quoteName($fields['language']) - ); + ->join('LEFT', $db->quoteName('#__languages', 'l') . ' ON ' . $db->quoteName('l.lang_code') . ' = ' . $db->quoteName($fields['language'])); // Join over the associations. $query->select('COUNT(' . $db->quoteName('asso2.id') . ') > 1 AS ' . $db->quoteName('association')) @@ -332,9 +330,7 @@ protected function getListQuery() // Join over the menu types. $query->select($db->quoteName('mt.title', 'menutype_title')) ->select($db->quoteName('mt.id', 'menutypeid')) - ->join('LEFT', $db->quoteName('#__menu_types', 'mt') - . ' ON ' . $db->quoteName('mt.menutype') . ' = ' . $db->quoteName($fields['menutype']) - ); + ->join('LEFT', $db->quoteName('#__menu_types', 'mt') . ' ON ' . $db->quoteName('mt.menutype') . ' = ' . $db->quoteName($fields['menutype'])); $groupby[] = 'mt.title'; $groupby[] = 'mt.id'; @@ -451,7 +447,7 @@ protected function getListQuery() if ($assocStateField !== 'all') { - // not associated + // Not associated if ($assocStateField === 'not_associated') { $languageQuery = $db->getQuery(true) @@ -460,41 +456,41 @@ protected function getListQuery() $db->setQuery($languageQuery); $countLanguages = $db->loadResult(); - // get all keys where not all languages are associated + // Get all keys where not all languages are associated. $assocQuery = $db->getQuery(true) ->select($db->quoteName('key')) ->from($db->quoteName('#__associations')) ->group($db->quoteName('key')) ->having('COUNT(*) < ' . $countLanguages); - // join over associations where id does not exists + // Join over associations where id does not exists $query->where('((' . $db->quoteName('asso.id') . ' IS NULL )' - // or if we are on the childlanguage and there is no master language + // or if we are on the child language and there is no master language . ' OR ( ' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quote('-1') . ')' - // or a child of the master does not exist + // or a child of the master does not exist. . ' OR ( ' . $db->quoteName('asso.key') . ' IN (' . $assocQuery . ') AND ' . $db->quoteName('asso.parent_id') . ' = ' . $db->quote('0') . ')' . ')'); } - // outdated + // Outdated if ($assocStateField === 'outdated') { - // if we are on the masterlanguage and we check the state of the children + // If we are on the masterlanguage and we check the state of the children $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') . ' AND ' . $db->quoteName('asso2.assocParams') . ' < ' . $db->quoteName('asso.assocParams') . ')' - // if we are on the childlanguage we check its state comparing to its master + // or we are on the child language and we check its state comparing to its master. . ' OR (' . $db->quoteName('asso.assocParams') . ' < ' . $db->quoteName('asso2.assocParams') . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.parent_id') . '))'); } - // up-to-date + // Up-to-date if ($assocStateField === 'up_to_date') { - // if we are on the masterlanguage and we check the state of the children + // If we are on the masterlanguage and we check the state of the children $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') . ' AND ' . $db->quoteName('asso2.assocParams') . ' = ' . $db->quoteName('asso.assocParams') . ')' - // if we are on the childlanguage we check its state comparing to its master + // or we are on the child language and we check its state comparing to its master. . ' OR (' . $db->quoteName('asso.assocParams') . ' = ' . $db->quoteName('asso2.assocParams') . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.parent_id') . '))'); } diff --git a/administrator/components/com_associations/View/Associations/HtmlView.php b/administrator/components/com_associations/View/Associations/HtmlView.php index 157d4b0623bac..55cea3d6c42a7 100644 --- a/administrator/components/com_associations/View/Associations/HtmlView.php +++ b/administrator/components/com_associations/View/Associations/HtmlView.php @@ -89,7 +89,6 @@ public function display($tpl = null) $this->filterForm->setValue('language', null, $this->state->get('language')); } - // Get default values and set these to selected to the select boxes if ($this->state->get('assocstate')) { $this->filterForm->setValue('assocstate', null, $this->state->get('assocstate')); @@ -153,10 +152,9 @@ public function display($tpl = null) unset($this->activeFilters['assocstate']); //Remove association state filter depending on global master language - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $globalMasterLang = Associations::getGlobalMasterLanguage(); - if(!$globalMasterLanguage){ - unset($this->activeFilters['assocstate']); + if(!$globalMasterLang){ $this->filterForm->removeField('assocstate', 'filter'); } @@ -269,8 +267,7 @@ protected function addToolbar() { $toolbar->confirmButton('purge') ->text('COM_ASSOCIATIONS_PURGE') - ->message( - (isset($this->extensionName) && isset($languageKey)) + ->message((isset($this->extensionName) && isset($languageKey)) ? Text::plural('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT', (Text::_($this->extensionName) . ' > ' . Text::_($languageKey))) : Text::_('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT') ) diff --git a/administrator/components/com_associations/layouts/joomla/searchtools/default.php b/administrator/components/com_associations/layouts/joomla/searchtools/default.php index 459dba9ec13de..4bb0f9f83be83 100644 --- a/administrator/components/com_associations/layouts/joomla/searchtools/default.php +++ b/administrator/components/com_associations/layouts/joomla/searchtools/default.php @@ -41,7 +41,7 @@ $data['options'] = array_merge($customOptions, $data['options']); -$globalMasterLanguage = Associations::getGlobalMasterLanguage(); +$globalMasterLang = Associations::getGlobalMasterLanguage(); // Load search tools HTMLHelper::_('searchtools.form', $data['options']['formSelector'], $data['options']); @@ -61,7 +61,7 @@ input->get('forcedLanguage', '', 'cmd') == '') : ?> filterForm->getField('language'); ?> - +
      @@ -72,7 +72,7 @@
      - + filterForm->getField('assocstate'); ?>
      diff --git a/administrator/components/com_associations/tmpl/associations/default.php b/administrator/components/com_associations/tmpl/associations/default.php index 3194a3430ed0b..fec863a4039f1 100644 --- a/administrator/components/com_associations/tmpl/associations/default.php +++ b/administrator/components/com_associations/tmpl/associations/default.php @@ -19,11 +19,11 @@ HTMLHelper::_('behavior.multiselect'); -$listOrder = $this->escape($this->state->get('list.ordering')); -$listDirn = $this->escape($this->state->get('list.direction')); -$canManageCheckin = Factory::getUser()->authorise('core.manage', 'com_checkin'); -$globalMasterLanguage = Associations::getGlobalMasterLanguage(); -$assocState = $this->escape($this->state->get('assocstate')); +$listOrder = $this->escape($this->state->get('list.ordering')); +$listDirn = $this->escape($this->state->get('list.direction')); +$canManageCheckin = Factory::getUser()->authorise('core.manage', 'com_checkin'); +$globalMasterLang = Associations::getGlobalMasterLanguage(); +$assocState = $this->escape($this->state->get('assocstate')); $iconStates = array( -2 => 'icon-trash', @@ -61,7 +61,7 @@ - + @@ -131,7 +131,7 @@ - + extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout, true, $assocState); ?> diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index 4b9141da479f2..c4616fbcd70d8 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -632,7 +632,7 @@ public function save($data) } // Get association params before they get deleted - $associationsParams = MasterAssociationsHelper::getMasterDates($associations, $this->associationsContext); + $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, $this->associationsContext); // Get associationskey for edited item $db = $this->getDbo(); @@ -681,8 +681,9 @@ public function save($data) if (count($associations) > 1) { // If there is an association item with the globalMasterLanguage, then get his id - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); - $masterId = $associations[$globalMasterLanguage] ?? ''; + $globalMasterLang = Associations::getGlobalMasterLanguage(); + $masterId = $associations[$globalMasterLang] ?? ''; + // Id of the saved item $dataId = (int) $table->id; @@ -696,7 +697,7 @@ public function save($data) foreach ($associations as $id) { - $masterIdAndDateValues = MasterAssociationsHelper::setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $associationsParams, $oldKey); + $masterIdAndDateValues = MasterAssociationsHelper::getMasterValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $oldKey); $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($masterIdAndDateValues[0]) . ',' . $db->quote($masterIdAndDateValues[1])); diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index 57699ed4fd3dd..b6754d3da2768 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -11,9 +11,9 @@ defined('_JEXEC') or die; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Language\Associations; -use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; @@ -41,8 +41,11 @@ class AdministratorService public function association($catid, $extension = 'com_content') { // Defaults - $html = ''; - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $html = ''; + $globalMasterLang = Associations::getGlobalMasterLanguage(); + + // Check if versions are enabled. + $saveHistory = ComponentHelper::getParams($extension)->get('save_history', 0); // Get the associations if ($associations = CategoriesHelper::getAssociations($catid, $extension)) @@ -50,7 +53,7 @@ public function association($catid, $extension = 'com_content') $associations = ArrayHelper::toInteger($associations); // Get the associated categories - $db = Factory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true) ->select('c.id, c.title') ->select('l.sef as lang_sef') @@ -58,8 +61,8 @@ public function association($catid, $extension = 'com_content') ->from('#__categories as c') ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); - // Don't get the id of the item itself when there is no master language used - if (!$globalMasterLanguage) + // Don't get the id of the item itself when there is no master language used. + if (!$globalMasterLang) { $query->where('c.id != ' . $catid); } @@ -78,19 +81,19 @@ public function association($catid, $extension = 'com_content') throw new \Exception($e->getMessage(), 500, $e); } - if ($globalMasterLanguage) + if ($globalMasterLang) { - // Check whether the current article is written in the global master language - $masterElement = (array_key_exists($catid, $items) - && ($items[$catid]->lang_code === $globalMasterLanguage)) + // Check if the current item is a master item. + $isMaster = (array_key_exists($catid, $items) && ($items[$catid]->lang_code === $globalMasterLang)) ? true : false; - // Check if there is a master item in the association and get his id if so - $masterId = array_key_exists($globalMasterLanguage, $associations) - ? $associations[$globalMasterLanguage] + // Check if there is a master item in the association and get his id if so. + $masterId = array_key_exists($globalMasterLang, $associations) + ? $associations[$globalMasterLang] : ''; + // Get master dates of each item of associations. $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_categories.item'); } @@ -98,77 +101,46 @@ public function association($catid, $extension = 'com_content') { foreach ($items as $key => &$item) { - $labelClass = 'badge-success'; - $languageTitle = $item->language_title; - $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; - $title = $item->title; - $url = Route::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); + $labelClass = 'badge-success'; + $masterInfo = ''; - if ($globalMasterLanguage) + if ($globalMasterLang) { - - // Don't continue for master, because it has been set here before + // Don't continue for master, because it has been set here before. if ($key === 'master') { continue; } - // Don't display other children if the current item is a child of the master language. - if (($key !== $catid) - && ($globalMasterLanguage !== $item->lang_code) - && !$masterElement) - { - unset($items[$key]); - } - - if ($key === $masterId) - { - $labelClass .= ' master-item'; - $languageTitle = $item->language_title . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); - } - else - { - // get association state of child when a master exists - if ($masterId && array_key_exists($key, $assocMasterDates) - && array_key_exists($masterId, $assocMasterDates)) - { - $associatedModifiedMaster = $assocMasterDates[$key]; - $lastModifiedMaster = $assocMasterDates[$masterId]; - - if ($associatedModifiedMaster < $lastModifiedMaster) - { - $labelClass = 'badge-warning'; - $title .= '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') . '
      '; - } - else - { - $title .= '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC') . '
      '; - } - } - } + $classAndMasterInfo = MasterAssociationsHelper::setMasterAndChildInfos($catid, $items, $key, $item, + $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); + $labelClass = $classAndMasterInfo[0]; + $masterInfo = $classAndMasterInfo[1]; } + $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; + $url = Route::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); + $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' + . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . $masterInfo; $classes = 'badge ' . $labelClass; - $tooltip = '' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '
      ' - . htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); - $item->link = '' . $text . '' + $item->link = '' . $text . '' . ''; - // Reorder the array, so the master item gets to the first place - if ($item->lang_code === $globalMasterLanguage) + // Reorder the array, so the master item gets to the first place. + if ($item->lang_code === $globalMasterLang) { $items = array('master' => $items[$key]) + $items; unset($items[$key]); } } - // If a master item doesn't exist, display that there is no association with the master language - if ($globalMasterLanguage && !$masterId) + // If a master item doesn't exist, display that there is no association with the master language. + if ($globalMasterLang && !$masterId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLanguage); + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang); - // add this on the top of the array + // Add this on the top of the array. $items = array('master' => array('link' => $link)) + $items; } } diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index eb824f4d1b083..9ba59b80ebca6 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -40,12 +40,11 @@ class AdministratorService public function association($contactid) { // Defaults - $html = ''; - $masterInfo = ''; - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $html = ''; + $globalMasterLang = Associations::getGlobalMasterLanguage(); // Check if versions are enabled - $saveHistory = ComponentHelper::getParams('com_contact')->get('save_history', 0); + $saveHistory = ComponentHelper::getParams('com_contact')->get('save_history', 0); // Get the associations if ($associations = Associations::getAssociations('com_contact', '#__contact_details', 'com_contact.item', $contactid)) @@ -65,8 +64,8 @@ public function association($contactid) ->join('LEFT', '#__categories as cat ON cat.id=c.catid') ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); - // Don't get the id of the item itself when there is no master language used - if (!$globalMasterLanguage) + // Don't get the id of the item itself when there is no master language used. + if (!$globalMasterLang) { $query->where('c.id != ' . $contactid); } @@ -85,76 +84,45 @@ public function association($contactid) throw new \Exception($e->getMessage(), 500, $e); } - if ($globalMasterLanguage) + if ($globalMasterLang) { - // Check whether the current contact is written in the global master language - $masterElement = (array_key_exists($contactid, $items) - && ($items[$contactid]->lang_code === $globalMasterLanguage)) + // Check if current item is the master item. + $isMaster = (array_key_exists($contactid, $items) && ($items[$contactid]->lang_code === $globalMasterLang)) ? true : false; - // Check if there is a master item in the association and get his id if so - $masterId = array_key_exists($globalMasterLanguage, $associations) - ? $associations[$globalMasterLanguage] + // Check if there is a master item in the association and get his id if so. + $masterId = array_key_exists($globalMasterLang, $associations) + ? $associations[$globalMasterLang] : ''; - $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_contact.item'); + // Get master dates of each item of associations. + $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_contact.item'); } if ($items) { foreach ($items as $key => &$item) { - $labelClass = 'badge-success'; - $text = strtoupper($item->lang_sef); - $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); + $masterInfo = ''; + $labelClass = 'badge-success'; - if ($globalMasterLanguage) + if ($globalMasterLang) { - // Don't continue for master, because it has been set just before as new array item if ($key === 'master') { continue; } - // Don't display other children if the current item is a child of the master language. - if (($key !== $contactid) - && ($globalMasterLanguage !== $item->lang_code) - && !$masterElement) - { - unset($items[$key]); - } - - if ($key === $masterId) - { - $labelClass .= ' master-item'; - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); - $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); - } - else - { - // get association state of child - if ($masterId && array_key_exists($key, $assocMasterDates) && array_key_exists($masterId, $assocMasterDates)) - { - $associatedModifiedMaster = $assocMasterDates[$key]; - $lastModifiedMaster = $assocMasterDates[$masterId]; - - if ($associatedModifiedMaster < $lastModifiedMaster) - { - $labelClass = 'badge-warning'; - $masterInfo = $saveHistory - ? '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') - : '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); - } - else - { - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); - } - } - } + $classAndMasterInfo = MasterAssociationsHelper::setMasterAndChildInfos($contactid, $items, $key, $item, + $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); + $labelClass = $classAndMasterInfo[0]; + $masterInfo = $classAndMasterInfo[1]; } + $text = strtoupper($item->lang_sef); + $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; $classes = 'badge ' . $labelClass; @@ -163,7 +131,7 @@ public function association($contactid) . ''; // Reorder the array, so the master item gets to the first place - if ($item->lang_code === $globalMasterLanguage) + if ($item->lang_code === $globalMasterLang) { $items = array('master' => $items[$key]) + $items; unset($items[$key]); @@ -171,9 +139,9 @@ public function association($contactid) } // If a master item doesn't exist, display that there is no association with the master language - if ($globalMasterLanguage && !$masterId) + if ($globalMasterLang && !$masterId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLanguage); + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang); // add this on the top of the array $items = array('master' => array('link' => $link)) + $items; diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index 3fff01d624f78..f9d8519223e0e 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -41,9 +41,8 @@ class AdministratorService public function association($articleid) { // Defaults - $html = ''; - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); - $masterInfo = ''; + $html = ''; + $globalMasterLang = Associations::getGlobalMasterLanguage(); // Check if versions are enabled $saveHistory = ComponentHelper::getParams('com_content')->get('save_history', 0); @@ -57,7 +56,7 @@ public function association($articleid) } // Get the associated menu items - $db = Factory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true) ->select('c.*') ->select('l.sef as lang_sef') @@ -68,7 +67,7 @@ public function association($articleid) ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); // Don't get the id of the item itself when there is no master language used - if (!$globalMasterLanguage) + if (!$globalMasterLang) { $query->where('c.id != ' . $articleid); } @@ -87,19 +86,19 @@ public function association($articleid) throw new \Exception($e->getMessage(), 500, $e); } - if ($globalMasterLanguage) + if ($globalMasterLang) { - // Check whether the current article is written in the global master language - $masterElement = (array_key_exists($articleid, $items) - && ($items[$articleid]->lang_code === $globalMasterLanguage)) + // Check if the current item is a master item. + $isMaster = (array_key_exists($articleid, $items) && ($items[$articleid]->lang_code === $globalMasterLang)) ? true : false; // Check if there is a master item in the association and get his id if so - $masterId = array_key_exists($globalMasterLanguage, $associations) - ? $associations[$globalMasterLanguage] + $masterId = array_key_exists($globalMasterLang, $associations) + ? $associations[$globalMasterLang] : ''; + // Get master dates of each item of associations. $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_content.item'); } @@ -107,9 +106,10 @@ public function association($articleid) { foreach ($items as $key => &$item) { - $labelClass = 'badge-success'; + $masterInfo = ''; + $labelClass = 'badge-success'; - if ($globalMasterLanguage) + if ($globalMasterLang) { // Don't continue for master, because it has been set here before @@ -118,53 +118,23 @@ public function association($articleid) continue; } - // Don't display other children if the current item is a child of the master language. - if (($key !== $articleid) - && ($globalMasterLanguage !== $item->lang_code) - && !$masterElement) - { - unset($items[$key]); - } - - if ($key === $masterId) - { - $labelClass .= ' master-item'; - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); - } - else - { - // get association state of child - if ($masterId && array_key_exists($key, $assocMasterDates) && array_key_exists($masterId, $assocMasterDates)) - { - $associatedModifiedMaster = $assocMasterDates[$key]; - $lastModifiedMaster = $assocMasterDates[$masterId]; - - if ($associatedModifiedMaster < $lastModifiedMaster) - { - $labelClass = 'badge-warning'; - $masterInfo = $saveHistory - ? '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') - : '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); - } - else - { - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); - } - } - } + $classAndMasterInfo = MasterAssociationsHelper::setMasterAndChildInfos($articleid, $items, $key, $item, + $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); + $labelClass = $classAndMasterInfo[0]; + $masterInfo = $classAndMasterInfo[1]; } - $classes = 'badge ' . $labelClass; $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; + $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; - $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); + $classes = 'badge ' . $labelClass; $item->link = '' . $text . '' . ''; // Reorder the array, so the master item gets to the first place - if ($item->lang_code === $globalMasterLanguage) + if ($item->lang_code === $globalMasterLang) { $items = array('master' => $items[$key]) + $items; unset($items[$key]); @@ -172,9 +142,9 @@ public function association($articleid) } // If a master item doesn't exist, display that there is no association with the master language - if ($globalMasterLanguage && !$masterId) + if ($globalMasterLang && !$masterId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLanguage); + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang); // add this on the top of the array $items = array('master' => array('link' => $link)) + $items; diff --git a/administrator/components/com_menus/Model/ItemModel.php b/administrator/components/com_menus/Model/ItemModel.php index 901303500c6b3..d066648cdc6e9 100644 --- a/administrator/components/com_menus/Model/ItemModel.php +++ b/administrator/components/com_menus/Model/ItemModel.php @@ -1579,9 +1579,9 @@ public function save($data) if (count($associations) > 1) { - // If there is an association item with the globalMasterLanguage, then get his id - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); - $masterId = $associations[$globalMasterLanguage] ?? ''; + // If there is an associated item with the globalMasterLanguage, get its id. + $globalMasterLang = Associations::getGlobalMasterLanguage(); + $masterId = $associations[$globalMasterLang] ?? ''; // Adding new association for these items $key = md5(json_encode($associations)); @@ -1590,8 +1590,8 @@ public function save($data) foreach ($associations as $id) { - // If there is no master item in this association, then reset the parent_id to -1 - // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. + // If there is no master item in this association, then reset the master id. + // Otherwise, if the associated item is a master item, set its master id to 0, otherwise to the master Id. $masterIdValue = $masterId ? ($masterId === $id ? 0 : $masterId) : -1; $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($masterIdValue) . ',' . $db->quote(null)); } diff --git a/administrator/components/com_menus/Service/HTML/Menus.php b/administrator/components/com_menus/Service/HTML/Menus.php index a70366f48b411..b01787fc3432a 100644 --- a/administrator/components/com_menus/Service/HTML/Menus.php +++ b/administrator/components/com_menus/Service/HTML/Menus.php @@ -44,7 +44,7 @@ public function association($itemid) { // Defaults $html = ''; - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $globalMasterLang = Associations::getGlobalMasterLanguage(); // Get the associations if ($associations = MenusHelper::getAssociations($itemid)) @@ -60,7 +60,7 @@ public function association($itemid) ->where('m.id IN (' . implode(',', array_values($associations)) . ')'); // Don't get the id of the item itself when there is no master language used - if (!$globalMasterLanguage) + if (!$globalMasterLang) { $query->where('m.id != ' . $itemid); } @@ -79,17 +79,16 @@ public function association($itemid) throw new \Exception($e->getMessage(), 500); } - if ($globalMasterLanguage) + if ($globalMasterLang) { - // Check whether the current article is written in the global master language - $masterElement = (array_key_exists($itemid, $items) - && ($items[$itemid]->lang_code === $globalMasterLanguage)) + // Check if current item is the master item. + $masterElement = (array_key_exists($itemid, $items) && ($items[$itemid]->lang_code === $globalMasterLang)) ? true : false; // Check if there is a master item in the association and get his id if so - $masterId = array_key_exists($globalMasterLanguage, $associations) - ? $associations[$globalMasterLanguage] + $masterId = array_key_exists($globalMasterLang, $associations) + ? $associations[$globalMasterLang] : ''; } @@ -98,7 +97,7 @@ public function association($itemid) { foreach ($items as $key => &$item) { - if ($globalMasterLanguage) + if ($globalMasterLang) { // Don't continue for master, because it has been set here before if ($key === 'master') @@ -107,9 +106,7 @@ public function association($itemid) } // Don't display other children if the current item is a child of the master language. - if ($key !== $itemid - && $globalMasterLanguage !== $item->lang_code - && !$masterElement) + if ($key !== $itemid && $globalMasterLang !== $item->lang_code && !$masterElement) { unset($items[$key]); } @@ -125,7 +122,7 @@ public function association($itemid) . ''; // Reorder the array, so the master item gets to the first place - if ($item->lang_code === $globalMasterLanguage) + if ($item->lang_code === $globalMasterLang) { $items = array('master' => $items[$key]) + $items; unset($items[$key]); @@ -133,9 +130,9 @@ public function association($itemid) } // If a master item doesn't exist, display that there is no association with the master language - if ($globalMasterLanguage && !$masterId) + if ($globalMasterLang && !$masterId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLanguage); + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang); // add this on the top of the array $items = array('master' => array('link' => $link)) + $items; diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index a6b7e0a920a39..9db5a9302bc14 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -38,9 +38,8 @@ class AdministratorService public function association($newsfeedid) { // Defaults - $html = ''; - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); - $masterInfo = ''; + $html = ''; + $globalMasterLang = Associations::getGlobalMasterLanguage(); // Check if versions are enabled $saveHistory = ComponentHelper::getParams('com_newsfeeds')->get('save_history', 0); @@ -64,7 +63,7 @@ public function association($newsfeedid) ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); // Don't get the id of the item itself when there is no master language used - if (!$globalMasterLanguage) + if (!$globalMasterLang) { $query->where('c.id != ' . $newsfeedid); } @@ -83,19 +82,19 @@ public function association($newsfeedid) throw new \Exception($e->getMessage(), 500); } - if ($globalMasterLanguage) + if ($globalMasterLang) { - // Check whether the current newsfeed is written in the global master language - $masterElement = (array_key_exists($newsfeedid, $items) - && ($items[$newsfeedid]->lang_code === $globalMasterLanguage)) + // Check if current item is a master item. + $isMaster = (array_key_exists($newsfeedid, $items) && ($items[$newsfeedid]->lang_code === $globalMasterLang)) ? true : false; - // Check if there is a master item in the association and get his id if so - $masterId = array_key_exists($globalMasterLanguage, $associations) - ? $associations[$globalMasterLanguage] + // Check if there is a master item in the association and get his id if so. + $masterId = array_key_exists($globalMasterLang, $associations) + ? $associations[$globalMasterLang] : ''; + // Get master dates of each item of associations. $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_newsfeeds.item'); } @@ -103,9 +102,10 @@ public function association($newsfeedid) { foreach ($items as $key => &$item) { + $masterInfo = ''; $labelClass = 'badge-success'; - if ($globalMasterLanguage) + if ($globalMasterLang) { // Don't continue for master, because it has been set here before if ($key === 'master') @@ -113,53 +113,23 @@ public function association($newsfeedid) continue; } - // Don't display other children if the current item is a child of the master language. - if ($key !== $newsfeedid - && ($globalMasterLanguage !== $item->lang_code) - && !$masterElement) - { - unset($items[$key]); - } - - if ($key === $masterId) - { - $labelClass .= ' master-item'; - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); - } - else - { - // get association state of child - if ($masterId && array_key_exists($key, $assocMasterDates) && array_key_exists($masterId, $assocMasterDates)) - { - $associatedModifiedMaster = $assocMasterDates[$key]; - $lastModifiedMaster = $assocMasterDates[$masterId]; - - if ($associatedModifiedMaster < $lastModifiedMaster) - { - $labelClass = 'badge-warning'; - $masterInfo = $saveHistory - ? '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') - : '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); - } - else - { - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); - } - } - } + $classAndMasterInfo = MasterAssociationsHelper::setMasterAndChildInfos($newsfeedid, $items, $key, $item, + $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); + $labelClass = $classAndMasterInfo[0]; + $masterInfo = $classAndMasterInfo[1]; } - $classes = 'badge ' . $labelClass; $text = strtoupper($item->lang_sef); $url = Route::_('index.php?option=com_newsfeeds&task=newsfeed.edit&id=' . (int) $item->id); $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; + $classes = 'badge ' . $labelClass; $item->link = '' . $text . '' . ''; // Reorder the array, so the master item gets to the first place - if ($item->lang_code === $globalMasterLanguage) + if ($item->lang_code === $globalMasterLang) { $items = array('master' => $items[$key]) + $items; unset($items[$key]); @@ -167,9 +137,9 @@ public function association($newsfeedid) } // If a master item doesn't exist, display that there is no association with the master language - if ($globalMasterLanguage && !$masterId) + if ($globalMasterLang && !$masterId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLanguage); + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang); // add this on the top of the array $items = array('master' => array('link' => $link)) + $items; diff --git a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini index ccafa8f48e6a4..a30c6a9bf873a 100644 --- a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini +++ b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini @@ -13,7 +13,7 @@ PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_LABEL="Global Master Lang PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_DESC="Note that changing this value will overwrite all existing Master Child relationships with their states." PLG_SYSTEM_LANGUAGEFILTER_FIELD_ITEM_ASSOCIATIONS_LABEL="Item Associations" PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_LABEL="Set a Master Language?" -PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_DESC="When enabled, a master-child relationship is added between the languages, depending on the selected master language. This adds an additional 'outdated' state to a child element depending on its master. Please enable versions to get a comparison view for outdated items. If this field is disabled, functions dependent on this data are not available." +PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_DESC="When enabled, a master-child relationship is added between the languages. This adds an additional 'outdated' association state to a child item depending on its master. Please activate versions to get a comparison view for outdated items. If this field is disabled, functions dependent on this data are not available." PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LABEL="Add x-default Meta Tag" PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LANGUAGE_LABEL="x-default Language" PLG_SYSTEM_LANGUAGEFILTER_OPTION_DEFAULT_LANGUAGE="Default frontend language" diff --git a/installation/src/Model/LanguagesModel.php b/installation/src/Model/LanguagesModel.php index 32f95ca95f329..c2c065ab4809a 100644 --- a/installation/src/Model/LanguagesModel.php +++ b/installation/src/Model/LanguagesModel.php @@ -1407,21 +1407,21 @@ public function addBlogMenuItem($itemLanguage, $categoryId) public function addAssociations($groupedAssociations) { $db = Factory::getDbo(); - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); + $globalMasterLang = Associations::getGlobalMasterLanguage(); foreach ($groupedAssociations as $context => $associations) { - // If there is an association item with the globalMasterLanguage, then get his id - $masterID = $associations[$globalMasterLanguage] ?? ''; + // If there is an association item with the globalMasterLanguage, get his id. + $masterId = $associations[$globalMasterLang] ?? ''; $key = md5(json_encode($associations)); $query = $db->getQuery(true) ->insert('#__associations'); foreach ($associations as $language => $id) { - // If there is no master item in this association, then reset the parent_id to -1 - // Otherwise, if the association item is a master item, set the parent_id to 0, otherwise set it to the master ID. - $masterIdValue = $masterID ? ($masterID === $id ? 0 : $masterID) : -1; + // If there is no master item in this association, then reset the master_id to -1 + // Otherwise, if the association item is a master item set the master_id to 0, otherwise to the masterId. + $masterIdValue = $masterId ? ($masterId === $id ? 0 : $masterId) : -1; $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($masterIdValue) . ',' . $db->quote('')); } diff --git a/libraries/src/Language/Associations.php b/libraries/src/Language/Associations.php index c9c47ac0cd1a5..a50e1036054be 100644 --- a/libraries/src/Language/Associations.php +++ b/libraries/src/Language/Associations.php @@ -42,7 +42,7 @@ class Associations public static function getAssociations($extension, $tablename, $context, $id, $pk = 'id', $aliasField = 'alias', $catField = 'catid', $advClause = array()) { - $globalMasterLanguage = self::getGlobalMasterLanguage(); + $globalMasterLang = self::getGlobalMasterLanguage(); // To avoid doing duplicate database queries. static $multilanguageAssociations = array(); @@ -128,7 +128,7 @@ public static function getAssociations($extension, $tablename, $context, $id, $p foreach ($items as $tag => $item) { - if ($globalMasterLanguage) + if ($globalMasterLang) { // If a global master language is set, we need all items of an associations $multilanguageAssociations[$queryKey][$tag] = $item; @@ -197,7 +197,7 @@ public static function getGlobalMasterLanguage() static $tested = false; // Status of global master language parameter. - static $globalMasterLanguage = ''; + static $globalMasterLang = ''; if (self::isEnabled()) { @@ -209,13 +209,13 @@ public static function getGlobalMasterLanguage() if (!empty($plugin)) { $params = new Registry($plugin->params); - $globalMasterLanguage = $params->get('global_master_language'); + $globalMasterLang = $params->get('global_master_language'); } $tested = true; } } - return $globalMasterLanguage ?? ''; + return $globalMasterLang ?? ''; } } diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 3cbbe14e7d9ca..f4d8b1feee696 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -1363,13 +1363,14 @@ public function save($data) if (count($associations) > 1) { // If there is an association item with the globalMasterLanguage, then get his id - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); - $masterId = $associations[$globalMasterLanguage] ?? ''; + $globalMasterLang = Associations::getGlobalMasterLanguage(); + $masterId = $associations[$globalMasterLang] ?? ''; + // get id of the item that get saved - $dataId = (int) $table->id; + $dataId = (int) $table->id; // Get the latest modified date of master item - $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName(), $table->typeAlias); + $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName(), $table->typeAlias); // Adding new association for these items $key = md5(json_encode($associations) . $context); @@ -1377,7 +1378,7 @@ public function save($data) foreach ($associations as $id) { - $masterIdAndDateValues = MasterAssociationsHelper::setMasterLanguageValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $old_key); + $masterIdAndDateValues = MasterAssociationsHelper::getMasterValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $old_key); $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($masterIdAndDateValues[0]) . ',' . $db->quote($masterIdAndDateValues[1])); @@ -1663,16 +1664,16 @@ public function editAssociations($data) } } - $globalMasterLanguage = Associations::getGlobalMasterLanguage(); - $isMaster = $data['language'] === $globalMasterLanguage; + $globalMasterLang = Associations::getGlobalMasterLanguage(); + $isMaster = $data['language'] === $globalMasterLang; // If a global Master Language is set and the current item is a child item, then open the master item as reference and the child as target - if ($globalMasterLanguage && !$isMaster) + if ($globalMasterLang && !$isMaster) { // if there is an associated master item change reference id. - if($data['associations'][$globalMasterLanguage]) + if($data['associations'][$globalMasterLang]) { - $id = $data['associations'][$globalMasterLanguage]; + $id = $data['associations'][$globalMasterLang]; $target = '&target=' . $data['language'] . '%3A' . $data['id'] . '%3Aedit'; } } diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index 800b0141386e6..04ac129e0346f 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -99,7 +99,7 @@ class PlgSystemLanguageFilter extends CMSPlugin * Constructor. * * @param object &$subject The object to observe - * @param array $config An optional associative array of configuration settings. + * @param array $config An optional associative array of configuration settings. * * @since 1.6 */ @@ -969,20 +969,19 @@ private function getLanguageCookie() /** * Before Saving extensions - * Method is called when an extension is going to be saved - * change parameters for master language because they depends on other parameters + * Method is called when an extension is going to be saved. + * Change parameters for master language as they depends on other parameters. * - * @param string $context The extension - * @param JTable $table DataBase Table object - * @param boolean $isNew If the extension is new or not + * @param string $context The extension + * @param JTable $table DataBase Table object * * @return void * * @since 4.0.0 */ - public function onExtensionBeforeSave($context, $table, $isNew) + public function onExtensionBeforeSave($context, $table) { - // Get the params to save + // Get the parameters which are to be saved. $params = json_decode($table->params); $tableElement = $table->element; $pluginStatus = $table->enabled; @@ -993,13 +992,12 @@ public function onExtensionBeforeSave($context, $table, $isNew) return true; } - // If the plugin and the parameter item associations are enabled then set the correct value for the global master language + // If the plugin and the parameter item_associations are enabled then set the correct value for the global master language. if ($pluginStatus && $itemAssocStatus) { - $globalMasterLanguage = ($params->use_master_language === '1') + $params->global_master_language = ($params->use_master_language === '1') ? $params->global_master_language : ''; - $params->global_master_language = $globalMasterLanguage; } // Reset parameters for master language else @@ -1016,19 +1014,18 @@ public function onExtensionBeforeSave($context, $table, $isNew) /** * After save extensions - * Method is called when an extension has been saved + * Method is called when an extension has been saved. * * @param string $context The extension * @param JTable $table DataBase Table object - * @param boolean $isNew If the extension is new or not * * @return void * * @since 4.0.0 */ - public function onExtensionAfterSave($context, $table, $isNew) + public function onExtensionAfterSave($context, $table) { - // get the params that have been saved + // Get the parameters which have been saved $params = json_decode($table->params); $tableElement = $table->element; @@ -1037,24 +1034,25 @@ public function onExtensionAfterSave($context, $table, $isNew) return true; } - // just set master items when the global master language has changed. + // Only set master items if the global master language has changed. if ($this->hasMasterLangChanged) { $this->_setMasterItem($params->global_master_language); } + unset($this->hasMasterLangChanged); } /** - * Method to set the master of an association. - * This resets all the current master ids and the modified date and set these new. - * Master and children will be up-to-date, as they get the same modified date + * Method to set the master id and modified dates to all associated items. + * This resets all current master ids and modified dates and set these new. + * Master and children will be up-to-date, as they get the same modified date. * * @param string $language The global master language * * @return boolean Returns true on success, false on failure. * - * @throws \Exception + * @throws Exception * * @since 4.0.0 */ @@ -1063,7 +1061,7 @@ private function _setMasterItem($language) $db = Factory::getDbo(); $masterLanguage = $language; - // if there is no global masterlanguage set, set all parent_ids to -1 and assocParams to null + // If there is no global masterlanguage set, set all master ids to -1 and master dates to null if (!$masterLanguage) { $resetQuery = $db->getQuery(true) @@ -1083,8 +1081,8 @@ private function _setMasterItem($language) } else { - // get every different key - $keyQuery = $db->getQuery(true) + // Get every different key + $keyQuery = $db->getQuery(true) ->select($db->quoteName('key')) ->from($db->quoteName('#__associations')) ->group($db->quoteName('key')) @@ -1093,13 +1091,15 @@ private function _setMasterItem($language) foreach ($assocKeys as $value) { - //get the context of the association with the current key + // Get the context of this association with the current key $contextQuery = $db->getQuery(true) ->select($db->quoteName('context')) ->from($db->quoteName('#__associations')) ->where($db->quoteName('key') . ' = ' . $db->quote($value)); $assocContext = $db->setQuery($contextQuery)->loadResult(); + // Get the right table to search for modified date or save_date from history + $checkCategoryComponent = ''; $component = explode('.', $assocContext)[0]; @@ -1119,27 +1119,27 @@ private function _setMasterItem($language) $modified = ($component === 'com_menus') ? '' : $db->quoteName('e.modified'); } - // get ids of items with the global master language + // Get ids of items with the global master language $subQuery = $db->getQuery(true) ->select($db->quoteName('e.id')) ->from($fromTable) ->where($db->quoteName('e.language') . ' = ' . $db->quote($masterLanguage)); - // get master id of an item that has the global master language + // Get master id of an item that has the global master language $masterQuery = $db->getQuery(true) ->select($db->quoteName('id')) ->from('#__associations') ->where($db->quoteName('id') . ' IN (' . $subQuery . ')') ->where($db->quoteName('key') . ' = ' . $db->quote($value)); - $masterId = $db->setQuery($masterQuery)->loadResult(); + $masterId = $db->setQuery($masterQuery)->loadResult(); - // Get master modified date + // Get masters modified date if ($modified) { - // get the context of this category + // Get the context of this category if ($checkCategoryComponent) { - $categoryQuery = $db->getQuery(true) + $categoryQuery = $db->getQuery(true) ->select($checkCategoryComponent) ->from($fromTable) ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); @@ -1147,10 +1147,10 @@ private function _setMasterItem($language) $typeAlias = $categoryMasterExtension . '.category'; } - $component = $categoryMasterExtension ?? $component; + $component = $categoryMasterExtension ?? $component; $saveHistory = ComponentHelper::getParams($component)->get('save_history', 0); - // if versions are enabled get the save_data of the master item from history table otherwise use the modified date + // If versions are enabled get the save_date of the master item from history table otherwise use the modified date if ($saveHistory) { $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); @@ -1172,7 +1172,7 @@ private function _setMasterItem($language) $masterModified = $modified ? $masterModified : null; $masterId = $masterId ?? -1; - // Set the master item as parent and set his modified date + // Set the id and the modified date of the master item. $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) ->set($db->quoteName('parent_id') . ' = ' . $db->quote(0)) @@ -1191,7 +1191,7 @@ private function _setMasterItem($language) return false; } - // Set the master id and modified date to the children + // Set the id and modified date of the master item to the children $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) ->set($db->quoteName('parent_id') . ' = ' . $db->quote($masterId)) From ca7d5b0d4bee606d611aeb308a6c057635150e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 1 Jul 2019 22:12:56 +0200 Subject: [PATCH 38/98] rename table columns for master lang --- .../Helper/MasterAssociationsHelper.php | 2 +- .../Model/AssociationMasterModel.php | 8 +++---- .../Model/AssociationModel.php | 21 ++++++++++--------- .../Model/AssociationsModel.php | 18 +++++++++------- .../en-GB/en-GB.plg_system_languagefilter.ini | 4 ++-- installation/sql/mysql/joomla.sql | 4 ++-- installation/sql/postgresql/joomla.sql | 7 ++++--- .../system/languagefilter/languagefilter.php | 12 +++++------ 8 files changed, 40 insertions(+), 36 deletions(-) diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 5f414fcdfc4f4..c33ec292c8290 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -78,7 +78,7 @@ public static function getMasterDates($associations, $context) } $query = $db->getQuery(true) - ->select($db->quoteName('assocParams')) + ->select($db->quoteName('master_date')) ->from($db->quoteName('#__associations')) ->where($db->quoteName('id') . ' = ' . $db->quote($id)) ->where($db->quoteName('context') . ' = ' . $db->quote($context)); diff --git a/administrator/components/com_associations/Model/AssociationMasterModel.php b/administrator/components/com_associations/Model/AssociationMasterModel.php index a0458fe8d606c..5024de6f2f48c 100644 --- a/administrator/components/com_associations/Model/AssociationMasterModel.php +++ b/administrator/components/com_associations/Model/AssociationMasterModel.php @@ -43,18 +43,18 @@ public function update($childId, $masterId, $itemtype) { $db = Factory::getDbo(); $subQuery = $db->getQuery(true) - ->select($db->quoteName('assocParams')) + ->select($db->quoteName('master_date')) ->from($db->quoteName('#__associations')) ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)) - ->where($db->quoteName('parent_id') . ' = ' . $db->quote(0)) + ->where($db->quoteName('master_id') . ' = ' . $db->quote(0)) ->where($db->quoteName('context') . ' = ' . $db->quote($context)); $masterModified = $db->setQuery($subQuery)->loadResult(); $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('assocParams') . ' = ' . $db->quote($masterModified)) + ->set($db->quoteName('master_date') . ' = ' . $db->quote($masterModified)) ->where($db->quoteName('id') . ' = ' . $db->quote($childId)) - ->where($db->quoteName('parent_id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('master_id') . ' = ' . $db->quote($masterId)) ->where($db->quoteName('context') . ' = ' . $db->quote($context)); $db->setQuery($query); diff --git a/administrator/components/com_associations/Model/AssociationModel.php b/administrator/components/com_associations/Model/AssociationModel.php index 57fd64515135c..455c3b2e0d2e5 100644 --- a/administrator/components/com_associations/Model/AssociationModel.php +++ b/administrator/components/com_associations/Model/AssociationModel.php @@ -42,15 +42,16 @@ public function getForm($data = array(), $loadData = true) /** * Method to get the history version ids of a master item. * - * @param integer $masterId Id of the master item - * @param integer $targetId Id of an child item - * @param string $extensionName The extension name with com_ - * @param string $typeName The item type - * @param integer $typeId the content type id + * @param integer $masterId Id of the master item + * @param integer $targetId Id of an child item + * @param string $extensionName The extension name with com_ + * @param string $typeName The item type + * @param integer $typeId the content type id * - * @return array of version history ids + * @return array Array containing two version history ids */ - public function getMasterCompareValues($masterId, $targetId, $extensionName, $typeName, $typeId){ + public function getMasterCompareValues($masterId, $targetId, $extensionName, $typeName, $typeId) + { $context = ($typeName === 'category') ? 'com_categories.item' @@ -58,7 +59,7 @@ public function getMasterCompareValues($masterId, $targetId, $extensionName, $ty $db = Factory::getDbo(); $masterQuery = $db->getQuery(true) - ->select($db->quoteName('assocParams')) + ->select($db->quoteName('master_date')) ->from($db->quoteName('#__associations')) ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)) ->where($db->quoteName('context') . ' = ' . $db->quote($context)); @@ -73,10 +74,10 @@ public function getMasterCompareValues($masterId, $targetId, $extensionName, $ty $latestVersionId = $db->setQuery($latestVersionQuery)->loadResult(); $childQuery = $db->getQuery(true) - ->select($db->quoteName('assocParams')) + ->select($db->quoteName('master_date')) ->from($db->quoteName('#__associations')) ->where($db->quoteName('id') . ' = ' . $db->quote($targetId)) - ->where($db->quoteName('parent_id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('master_id') . ' = ' . $db->quote($masterId)) ->where($db->quoteName('context') . ' = ' . $db->quote($context)); $childMasterDate = $db->setQuery($childQuery)->loadResult(); diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 57a74aebc6138..370ba8f09c808 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -84,7 +84,9 @@ protected function populateState($ordering = 'ordering', $direction = 'asc') // Set language select box to default site language or if set to the master language as default. $globalMasterLang = Associations::getGlobalMasterLanguage(); - $defaultLanguage = $globalMasterLang ?? ComponentHelper::getParams('com_languages')->get('site'); + $langParam = ComponentHelper::getParams('com_languages'); + + $defaultLanguage = empty($globalMasterLang) ? $langParam->get('site') : $globalMasterLang; $defaultItemType = 'com_content.article'; // Adjust the context to support modal layouts. @@ -478,21 +480,21 @@ protected function getListQuery() { // If we are on the masterlanguage and we check the state of the children $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') - . ' AND ' . $db->quoteName('asso2.assocParams') . ' < ' . $db->quoteName('asso.assocParams') . ')' + . ' AND ' . $db->quoteName('asso2.master_date') . ' < ' . $db->quoteName('asso.master_date') . ')' // or we are on the child language and we check its state comparing to its master. - . ' OR (' . $db->quoteName('asso.assocParams') . ' < ' . $db->quoteName('asso2.assocParams') - . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.parent_id') . '))'); + . ' OR (' . $db->quoteName('asso.master_date') . ' < ' . $db->quoteName('asso2.master_date') + . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.master_id') . '))'); } // Up-to-date if ($assocStateField === 'up_to_date') { // If we are on the masterlanguage and we check the state of the children - $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') - . ' AND ' . $db->quoteName('asso2.assocParams') . ' = ' . $db->quoteName('asso.assocParams') . ')' + $query->where('((' . $db->quoteName('asso2.master_id') . ' = ' . $db->quoteName('asso.id') + . ' AND ' . $db->quoteName('asso2.master_date') . ' = ' . $db->quoteName('asso.master_date') . ')' // or we are on the child language and we check its state comparing to its master. - . ' OR (' . $db->quoteName('asso.assocParams') . ' = ' . $db->quoteName('asso2.assocParams') - . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.parent_id') . '))'); + . ' OR (' . $db->quoteName('asso.master_date') . ' = ' . $db->quoteName('asso2.master_date') + . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.master_id') . '))'); } } diff --git a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini index a30c6a9bf873a..6f2e6bee7aae0 100644 --- a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini +++ b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini @@ -10,10 +10,10 @@ PLG_SYSTEM_LANGUAGEFILTER_FIELD_AUTOMATIC_CHANGE_LABEL="Automatic Language Chang PLG_SYSTEM_LANGUAGEFILTER_FIELD_COOKIE_LABEL="Cookie Lifetime" PLG_SYSTEM_LANGUAGEFILTER_FIELD_DETECT_BROWSER_LABEL="Language Selection for new Visitors" PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_LABEL="Global Master Language" -PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_DESC="Note that changing this value will overwrite all existing Master Child relationships with their states." +PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_DESC="Note that changing this value will overwrite all existing Master Child relationships with their association states." PLG_SYSTEM_LANGUAGEFILTER_FIELD_ITEM_ASSOCIATIONS_LABEL="Item Associations" PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_LABEL="Set a Master Language?" -PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_DESC="When enabled, a master-child relationship is added between the languages. This adds an additional 'outdated' association state to a child item depending on its master. Please activate versions to get a comparison view for outdated items. If this field is disabled, functions dependent on this data are not available." +PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_DESC="When enabled, a master-child relationship is added between the languages. This adds an additional 'outdated' association state to a child item depending on its master. Enable versions to get a comparison view for outdated items. If this field is disabled, functions dependent on this data are not available." PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LABEL="Add x-default Meta Tag" PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LANGUAGE_LABEL="x-default Language" PLG_SYSTEM_LANGUAGEFILTER_OPTION_DEFAULT_LANGUAGE="Default frontend language" diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index d3ef3e36d1093..9440d52b42eca 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -107,8 +107,8 @@ CREATE TABLE IF NOT EXISTS `#__associations` ( `id` int(11) NOT NULL COMMENT 'A reference to the associated item.', `context` varchar(50) NOT NULL COMMENT 'The context of the associated item.', `key` char(32) NOT NULL COMMENT 'The key for the association computed from an md5 on associated ids.', - `parent_id` int(11) NOT NULL DEFAULT -1 COMMENT 'The parent master item of an association.', - `assocParams` text, + `master_id` int(11) NOT NULL DEFAULT -1 COMMENT 'The master item of an association.', + `master_date` text COMMENT 'The save or modified date of the master item.', PRIMARY KEY (`context`,`id`), KEY `idx_key` (`key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index 5ef04e0e5d38d..dc5c9767fe942 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -111,8 +111,8 @@ CREATE TABLE IF NOT EXISTS "#__associations" ( "id" int NOT NULL, "context" varchar(50) NOT NULL, "key" char(32) NOT NULL, - "parent_id" integer DEFAULT -1 NOT NULL, - "assocParams" text, + "master_id" integer DEFAULT -1 NOT NULL, + "master_date" text, CONSTRAINT "#__associations_idx_context_id" PRIMARY KEY ("context", "id") ); CREATE INDEX "#__associations_idx_key" ON "#__associations" ("key"); @@ -120,7 +120,8 @@ CREATE INDEX "#__associations_idx_key" ON "#__associations" ("key"); COMMENT ON COLUMN "#__associations"."id" IS 'A reference to the associated item.'; COMMENT ON COLUMN "#__associations"."context" IS 'The context of the associated item.'; COMMENT ON COLUMN "#__associations"."key" IS 'The key for the association computed from an md5 on associated ids.'; -COMMENT ON COLUMN "#__associations"."parent_id" IS 'The parent master item of an association.'; +COMMENT ON COLUMN "#__associations"."master_id" IS 'The master item of an association.'; +COMMENT ON COLUMN "#__associations"."master_date" IS 'The save or modified date of the master item.'; -- -- Table structure for table `#__banners` diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index 04ac129e0346f..e381326bd277d 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -1066,8 +1066,8 @@ private function _setMasterItem($language) { $resetQuery = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('parent_id') . ' = ' . -1) - ->set($db->quoteName('assocParams') . ' = ' . $db->quote(null)); + ->set($db->quoteName('master_id') . ' = ' . -1) + ->set($db->quoteName('master_date') . ' = ' . $db->quote(null)); $db->setQuery($resetQuery); try @@ -1175,8 +1175,8 @@ private function _setMasterItem($language) // Set the id and the modified date of the master item. $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('parent_id') . ' = ' . $db->quote(0)) - ->set($db->quoteName('assocParams') . ' = ' . $db->quote($masterModified)) + ->set($db->quoteName('master_id') . ' = ' . $db->quote(0)) + ->set($db->quoteName('master_date') . ' = ' . $db->quote($masterModified)) ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)) ->where($db->quoteName('key') . ' = ' . $db->quote($value)) ->where($db->quoteName('context') . ' = ' . $db->quote($assocContext)); @@ -1194,8 +1194,8 @@ private function _setMasterItem($language) // Set the id and modified date of the master item to the children $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('parent_id') . ' = ' . $db->quote($masterId)) - ->set($db->quoteName('assocParams') . ' = ' . $db->quote($masterModified)) + ->set($db->quoteName('master_id') . ' = ' . $db->quote($masterId)) + ->set($db->quoteName('master_date') . ' = ' . $db->quote($masterModified)) ->where($db->quoteName('id') . ' <> ' . $db->quote($masterId)) ->where($db->quoteName('key') . ' = ' . $db->quote($value)) ->where($db->quoteName('context') . ' = ' . $db->quote($assocContext)); From 7df0d4a402f54217b696e7aaaf8bdc8c1b4cd6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 1 Jul 2019 22:24:51 +0200 Subject: [PATCH 39/98] fix display assoc without other children --- .../com_associations/Helper/MasterAssociationsHelper.php | 4 ++-- .../com_categories/Service/HTML/AdministratorService.php | 7 ++++--- .../com_contact/Service/HTML/AdministratorService.php | 7 ++++--- .../com_content/Service/HTML/AdministratorService.php | 7 ++++--- .../com_newsfeeds/Service/HTML/AdministratorService.php | 7 ++++--- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index c33ec292c8290..00772daa2e7fa 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -203,7 +203,7 @@ public static function getMasterModifiedDate($masterId, $tableName, $typeAlias) * @param array $assocMasterDates Master Dates of each associated item. * @param boolean $saveHistory If Versions are enabled or not. * - * @return array the className and masterInfo for the association state + * @return array the className and masterInfo for the association state and the array $items back */ public static function setMasterAndChildInfos($itemId, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory) { @@ -245,6 +245,6 @@ public static function setMasterAndChildInfos($itemId, $items, $key, $item, $glo } } - return [$addClass, $masterInfo]; + return [$addClass, $masterInfo, $items]; } } diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index b6754d3da2768..9cc0641c778ae 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -112,10 +112,11 @@ public function association($catid, $extension = 'com_content') continue; } - $classAndMasterInfo = MasterAssociationsHelper::setMasterAndChildInfos($catid, $items, $key, $item, + $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos($catid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); - $labelClass = $classAndMasterInfo[0]; - $masterInfo = $classAndMasterInfo[1]; + $labelClass = $classMasterInfoItems[0]; + $masterInfo = $classMasterInfoItems[1]; + $items = $classMasterInfoItems[2]; } $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index 9ba59b80ebca6..df800603a0680 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -115,10 +115,11 @@ public function association($contactid) continue; } - $classAndMasterInfo = MasterAssociationsHelper::setMasterAndChildInfos($contactid, $items, $key, $item, + $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos($contactid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); - $labelClass = $classAndMasterInfo[0]; - $masterInfo = $classAndMasterInfo[1]; + $labelClass = $classMasterInfoItems[0]; + $masterInfo = $classMasterInfoItems[1]; + $items = $classMasterInfoItems[2]; } $text = strtoupper($item->lang_sef); diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index f9d8519223e0e..65dd02097ca90 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -118,10 +118,11 @@ public function association($articleid) continue; } - $classAndMasterInfo = MasterAssociationsHelper::setMasterAndChildInfos($articleid, $items, $key, $item, + $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos($articleid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); - $labelClass = $classAndMasterInfo[0]; - $masterInfo = $classAndMasterInfo[1]; + $labelClass = $classMasterInfoItems[0]; + $masterInfo = $classMasterInfoItems[1]; + $items = $classMasterInfoItems[2]; } $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index 9db5a9302bc14..54a16b09c4a58 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -113,10 +113,11 @@ public function association($newsfeedid) continue; } - $classAndMasterInfo = MasterAssociationsHelper::setMasterAndChildInfos($newsfeedid, $items, $key, $item, + $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos($newsfeedid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); - $labelClass = $classAndMasterInfo[0]; - $masterInfo = $classAndMasterInfo[1]; + $labelClass = $classMasterInfoItems[0]; + $masterInfo = $classMasterInfoItems[1]; + $items = $classMasterInfoItems[2]; } $text = strtoupper($item->lang_sef); From ef78227fe060e01865c49a5189dadf0c434ab707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 00:19:01 +0200 Subject: [PATCH 40/98] fix compare Master View when there is name instead of title used --- .../tmpl/compare/compareMaster.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php b/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php index 2dd4fbdef7a23..39e47096014cb 100644 --- a/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php +++ b/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php @@ -20,6 +20,15 @@ $object1 = $version1->data; $object2 = $version2->data; +$objLabel = ''; +if(array_key_exists('title', $object2)) +{ + $objLabel = $object2->title; +} +else if (array_key_exists('name', $object2)){ + $objLabel = $object2->name; +} + HTMLHelper::_('script', 'vendor/diff/diff.min.js', array('version' => 'auto', 'relative' => true)); HTMLHelper::_('script', 'com_associations/admin-compare-master.min.js', array('version' => 'auto', 'relative' => true)); HTMLHelper::_('stylesheet', 'com_associations/sidebyside.css', ['version' => 'auto', 'relative' => true]); @@ -28,10 +37,10 @@
      - data->title->label ?> + label ?>
      - +
      From 3a109bb99cf3f15761ff1e94534053c77b468bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 00:41:12 +0200 Subject: [PATCH 41/98] change links to edit association in other listviews with master --- .../Helper/MasterAssociationsHelper.php | 65 ++++++++++++++++--- .../Service/HTML/AdministratorService.php | 13 ++-- .../Service/HTML/AdministratorService.php | 13 ++-- .../Service/HTML/AdministratorService.php | 13 ++-- .../com_menus/Service/HTML/Menus.php | 23 +++++-- .../Service/HTML/AdministratorService.php | 13 ++-- 6 files changed, 105 insertions(+), 35 deletions(-) diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 00772daa2e7fa..44cc171cf23a5 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -14,6 +14,7 @@ use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Helper\ContentHistoryHelper; use Joomla\CMS\Language\Text; +use Joomla\CMS\Router\Route; use Joomla\CMS\Table\Table; defined('_JEXEC') or die; @@ -28,11 +29,13 @@ class MasterAssociationsHelper extends ContentHelper /** * Method to create a link for a child item that has no master item * - * @param string $globalMasterLang The global master language + * @param string $globalMasterLang The global master language + * @param integer $itemId The item id + * @param string $itemType The item type * * @return string the link for the not associated master item */ - public static function addNotAssociatedMasterLink($globalMasterLang) + public static function addNotAssociatedMasterLink($globalMasterLang, $itemId, $itemType) { $db = Factory::getDbo(); $query = $db->getQuery(true) @@ -42,11 +45,11 @@ public static function addNotAssociatedMasterLink($globalMasterLang) $db->setQuery($query); $globalMasterLangInfos = $db->loadAssoc(); - $classes = 'hasPopover badge badge-secondary'; - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); + $classes = 'badge badge-secondary'; + $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); $text = $globalMasterLangInfos['sef'] ? strtoupper($globalMasterLangInfos['sef']) : 'XX'; $title = Text::_('JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC'); - $url = ''; + $url = self::getAssociationUrl($itemId, $globalMasterLang, $itemType); $tooltip = '' . htmlspecialchars( $globalMasterLangInfos['title'], ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . $masterInfo; @@ -203,13 +206,14 @@ public static function getMasterModifiedDate($masterId, $tableName, $typeAlias) * @param array $assocMasterDates Master Dates of each associated item. * @param boolean $saveHistory If Versions are enabled or not. * - * @return array the className and masterInfo for the association state and the array $items back + * @return array the className and masterInfo for the association state, the array $items back and boolean if item needs update. */ public static function setMasterAndChildInfos($itemId, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory) { $addClass = 'badge-success'; $masterInfo = ''; + $update = false; // Don't display other children if the current item is a child of the master language. if (($key !== $itemId) && ($globalMasterLang !== $item->lang_code) && !$isMaster) @@ -232,19 +236,62 @@ public static function setMasterAndChildInfos($itemId, $items, $key, $item, $glo if ($associatedModifiedMaster < $lastModifiedMaster) { - $addClass = 'badge-warning'; + $update = true; + $addClass = 'badge-warning'; $masterInfo = $saveHistory ? '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') : '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); } else { - $addClass = 'badge-success'; + $addClass = 'badge-success'; $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); } } } - return [$addClass, $masterInfo, $items]; + return [$addClass, $masterInfo, $items, $update]; + } + + /** + * Method to get the association url for an item + * + * @param integer $itemId The item id + * @param string $globalMasterLang The global master language + * @param string $itemType The item type + * @param string $itemLang The current value from $items that is currently going through the foreach loop. + * @param integer $key The current key from $items that is currently going through the foreach loop. + * @param integer $masterId Id of the associated master item. + * @param boolean $needsUpdate If the item needs an update or not. + * + * @return string + */ + public static function getAssociationUrl($itemId, $globalMasterLang, $itemType, $itemLang = '', $key = '', $masterId = '', $needsUpdate = false) + { + $target = ''; + + if (empty($masterId)) + { + $target = $globalMasterLang . ':0:add'; + } + elseif ($key !== $masterId) + { + $target = $itemLang . ':' . $itemId . ':edit'; + } + + // Generate item Html. + $options = array( + 'option' => 'com_associations', + 'view' => 'association', + 'layout' => $needsUpdate ? 'update' : 'edit', + 'itemtype' => $itemType, + 'task' => 'association.edit', + 'id' => empty($masterId) ? $itemId : $masterId, + 'target' => $target, + ); + + $url = Route::_('index.php?' . http_build_query($options)); + + return $url; } } diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index 9cc0641c778ae..013478f878eec 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -103,6 +103,7 @@ public function association($catid, $extension = 'com_content') { $labelClass = 'badge-success'; $masterInfo = ''; + $url = Route::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); if ($globalMasterLang) { @@ -114,13 +115,15 @@ public function association($catid, $extension = 'com_content') $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos($catid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); - $labelClass = $classMasterInfoItems[0]; - $masterInfo = $classMasterInfoItems[1]; - $items = $classMasterInfoItems[2]; + $labelClass = $classMasterInfoItems[0]; + $masterInfo = $classMasterInfoItems[1]; + $items = $classMasterInfoItems[2]; + $needsUpdate = $classMasterInfoItems[3]; + + $url = MasterAssociationsHelper::getAssociationUrl($item->id, $globalMasterLang, $extension . '.category', $item->lang_code, $key, $masterId, $needsUpdate); } $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; - $url = Route::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . $masterInfo; $classes = 'badge ' . $labelClass; @@ -139,7 +142,7 @@ public function association($catid, $extension = 'com_content') // If a master item doesn't exist, display that there is no association with the master language. if ($globalMasterLang && !$masterId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang); + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $catid, $extension . '.category'); // Add this on the top of the array. $items = array('master' => array('link' => $link)) + $items; diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index df800603a0680..a1a9abe20a4c4 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -106,6 +106,7 @@ public function association($contactid) { $masterInfo = ''; $labelClass = 'badge-success'; + $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); if ($globalMasterLang) { @@ -117,13 +118,15 @@ public function association($contactid) $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos($contactid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); - $labelClass = $classMasterInfoItems[0]; - $masterInfo = $classMasterInfoItems[1]; - $items = $classMasterInfoItems[2]; + $labelClass = $classMasterInfoItems[0]; + $masterInfo = $classMasterInfoItems[1]; + $items = $classMasterInfoItems[2]; + $needsUpdate = $classMasterInfoItems[3]; + + $url = MasterAssociationsHelper::getAssociationUrl($item->id, $globalMasterLang, 'com_contact.contact', $item->lang_code, $key, $masterId, $needsUpdate); } $text = strtoupper($item->lang_sef); - $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; $classes = 'badge ' . $labelClass; @@ -142,7 +145,7 @@ public function association($contactid) // If a master item doesn't exist, display that there is no association with the master language if ($globalMasterLang && !$masterId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang); + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $contactid, 'com_contact.contact'); // add this on the top of the array $items = array('master' => array('link' => $link)) + $items; diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index 65dd02097ca90..f7f36c6657b3d 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -108,6 +108,7 @@ public function association($articleid) { $masterInfo = ''; $labelClass = 'badge-success'; + $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); if ($globalMasterLang) { @@ -120,13 +121,15 @@ public function association($articleid) $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos($articleid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); - $labelClass = $classMasterInfoItems[0]; - $masterInfo = $classMasterInfoItems[1]; - $items = $classMasterInfoItems[2]; + $labelClass = $classMasterInfoItems[0]; + $masterInfo = $classMasterInfoItems[1]; + $items = $classMasterInfoItems[2]; + $needsUpdate = $classMasterInfoItems[3]; + + $url = MasterAssociationsHelper::getAssociationUrl($item->id, $globalMasterLang, 'com_content.article', $item->lang_code, $key, $masterId, $needsUpdate); } $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; - $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; $classes = 'badge ' . $labelClass; @@ -145,7 +148,7 @@ public function association($articleid) // If a master item doesn't exist, display that there is no association with the master language if ($globalMasterLang && !$masterId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang); + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $articleid, 'com_content.article'); // add this on the top of the array $items = array('master' => array('link' => $link)) + $items; diff --git a/administrator/components/com_menus/Service/HTML/Menus.php b/administrator/components/com_menus/Service/HTML/Menus.php index b01787fc3432a..6888cf844945a 100644 --- a/administrator/components/com_menus/Service/HTML/Menus.php +++ b/administrator/components/com_menus/Service/HTML/Menus.php @@ -82,7 +82,7 @@ public function association($itemid) if ($globalMasterLang) { // Check if current item is the master item. - $masterElement = (array_key_exists($itemid, $items) && ($items[$itemid]->lang_code === $globalMasterLang)) + $isMaster = (array_key_exists($itemid, $items) && ($items[$itemid]->lang_code === $globalMasterLang)) ? true : false; @@ -97,6 +97,10 @@ public function association($itemid) { foreach ($items as $key => &$item) { + $masterInfo = ''; + $classes = 'badge badge-success'; + $url = Route::_('index.php?option=com_menus&task=item.edit&id=' . (int) $item->id); + if ($globalMasterLang) { // Don't continue for master, because it has been set here before @@ -106,17 +110,24 @@ public function association($itemid) } // Don't display other children if the current item is a child of the master language. - if ($key !== $itemid && $globalMasterLang !== $item->lang_code && !$masterElement) + if ($key !== $itemid && $globalMasterLang !== $item->lang_code && !$isMaster) { unset($items[$key]); } + + if ($key === $masterId) + { + $classes .= ' master-item'; + $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); + } + + $url = MasterAssociationsHelper::getAssociationUrl($item->id, $globalMasterLang, 'com_menus.item', $item->lang_code, $key, $masterId); } $text = strtoupper($item->lang_sef); - $url = Route::_('index.php?option=com_menus&task=item.edit&id=' . (int) $item->id); $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' - . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('COM_MENUS_MENU_SPRINTF', $item->menu_title); - $classes = 'badge badge-success'; + . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('COM_MENUS_MENU_SPRINTF', $item->menu_title) + . $masterInfo; $item->link = '' . $text . '' . ''; @@ -132,7 +143,7 @@ public function association($itemid) // If a master item doesn't exist, display that there is no association with the master language if ($globalMasterLang && !$masterId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang); + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $itemid, 'com_menus.item'); // add this on the top of the array $items = array('master' => array('link' => $link)) + $items; diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index 54a16b09c4a58..a45311580afba 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -104,6 +104,7 @@ public function association($newsfeedid) { $masterInfo = ''; $labelClass = 'badge-success'; + $url = Route::_('index.php?option=com_newsfeeds&task=newsfeed.edit&id=' . (int) $item->id); if ($globalMasterLang) { @@ -115,13 +116,15 @@ public function association($newsfeedid) $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos($newsfeedid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); - $labelClass = $classMasterInfoItems[0]; - $masterInfo = $classMasterInfoItems[1]; - $items = $classMasterInfoItems[2]; + $labelClass = $classMasterInfoItems[0]; + $masterInfo = $classMasterInfoItems[1]; + $items = $classMasterInfoItems[2]; + $needsUpdate = $classMasterInfoItems[3]; + + $url = MasterAssociationsHelper::getAssociationUrl($item->id, $globalMasterLang, 'com_newsfeeds.newsfeed', $item->lang_code, $key, $masterId, $needsUpdate); } $text = strtoupper($item->lang_sef); - $url = Route::_('index.php?option=com_newsfeeds&task=newsfeed.edit&id=' . (int) $item->id); $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; $classes = 'badge ' . $labelClass; @@ -140,7 +143,7 @@ public function association($newsfeedid) // If a master item doesn't exist, display that there is no association with the master language if ($globalMasterLang && !$masterId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang); + $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $newsfeedid, 'com_newsfeeds.newsfeed'); // add this on the top of the array $items = array('master' => array('link' => $link)) + $items; From 7f42c40ab5faa4899a29d46d554fb32a82a0496a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 10:36:36 +0200 Subject: [PATCH 42/98] fix missed renaming table column for master_id --- .../components/com_associations/Model/AssociationsModel.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 370ba8f09c808..0226dc8459173 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -468,10 +468,10 @@ protected function getListQuery() // Join over associations where id does not exists $query->where('((' . $db->quoteName('asso.id') . ' IS NULL )' // or if we are on the child language and there is no master language - . ' OR ( ' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quote('-1') . ')' + . ' OR ( ' . $db->quoteName('asso2.master_id') . ' = ' . $db->quote('-1') . ')' // or a child of the master does not exist. . ' OR ( ' . $db->quoteName('asso.key') . ' IN (' . $assocQuery . ') - AND ' . $db->quoteName('asso.parent_id') . ' = ' . $db->quote('0') . ')' + AND ' . $db->quoteName('asso.master_id') . ' = ' . $db->quote('0') . ')' . ')'); } @@ -479,7 +479,7 @@ protected function getListQuery() if ($assocStateField === 'outdated') { // If we are on the masterlanguage and we check the state of the children - $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') + $query->where('((' . $db->quoteName('asso2.master_id') . ' = ' . $db->quoteName('asso.id') . ' AND ' . $db->quoteName('asso2.master_date') . ' < ' . $db->quoteName('asso.master_date') . ')' // or we are on the child language and we check its state comparing to its master. . ' OR (' . $db->quoteName('asso.master_date') . ' < ' . $db->quoteName('asso2.master_date') From e6cdd7e1c23b834d72f3c0fea4f53a38e3bdc0a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 13:13:14 +0200 Subject: [PATCH 43/98] fix hound --- .../com_associations/js/admin-compare-master.es6.js | 2 +- .../com_associations/js/sidebysideupdate.es6.js | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/build/media_source/com_associations/js/admin-compare-master.es6.js b/build/media_source/com_associations/js/admin-compare-master.es6.js index 737f16188c3f2..0a9fcc98fc6b9 100644 --- a/build/media_source/com_associations/js/admin-compare-master.es6.js +++ b/build/media_source/com_associations/js/admin-compare-master.es6.js @@ -7,8 +7,8 @@ const compare = (original, changed) => { const display = changed.nextElementSibling; + const tagName = 'mark'; let className = 'same'; - let tagName = 'mark'; let tagElement = null; const diff = window.JsDiff.diffWords(original.textContent, changed.textContent); diff --git a/build/media_source/com_associations/js/sidebysideupdate.es6.js b/build/media_source/com_associations/js/sidebysideupdate.es6.js index 370546810a901..f7213eab32988 100644 --- a/build/media_source/com_associations/js/sidebysideupdate.es6.js +++ b/build/media_source/com_associations/js/sidebysideupdate.es6.js @@ -8,7 +8,6 @@ Joomla = window.Joomla || {}; 'use strict'; document.addEventListener('DOMContentLoaded', () => { - const referenceIframe = document.getElementById('reference-association'); const targetIframe = document.getElementById('target-association'); @@ -21,7 +20,7 @@ Joomla = window.Joomla || {}; Joomla.submitform(task); } else { window.frames['target-association'].Joomla.submitbutton(document.getElementById('adminForm').getAttribute('data-associatedview') + '.apply'); - document.getElementById("updateChild").click(); + document.getElementById('updateChild').click(); } }; @@ -30,7 +29,6 @@ Joomla = window.Joomla || {}; const reference = referenceIframe.contentDocument; const referenceDiff = reference.querySelector('#diff'); // Waiting until the reference has loaded before loading the target to avoid race conditions - let targetURL = Joomla.getOptions('targetSrc', false); if (referenceDiff) { @@ -49,10 +47,7 @@ Joomla = window.Joomla || {}; targetIframe.addEventListener('load', () => { if (targetIframe.getAttribute('src') != '') { - const targetLanguage = targetIframe.getAttribute('data-language'); - const targetId = targetIframe.getAttribute('data-id'); const target = targetIframe.contentDocument; - const targetLoadedId = target.querySelector('#jform_id').value || '0'; // Update language field with the selected language and then disable it. target.querySelector('#jform_language').setAttribute('disabled', ''); @@ -63,7 +58,6 @@ Joomla = window.Joomla || {}; // Iframe load finished, hide Joomla loading layer. Joomla.loadingLayer('hide'); } - }); }); -})(Joomla, document); \ No newline at end of file +})(Joomla, document); From 506059f4cdd9a90dea52e746285e073b6620bc39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 13:21:45 +0200 Subject: [PATCH 44/98] fix hound again --- .../com_associations/js/sidebysideupdate.es6.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/build/media_source/com_associations/js/sidebysideupdate.es6.js b/build/media_source/com_associations/js/sidebysideupdate.es6.js index f7213eab32988..7c53059a80aac 100644 --- a/build/media_source/com_associations/js/sidebysideupdate.es6.js +++ b/build/media_source/com_associations/js/sidebysideupdate.es6.js @@ -30,9 +30,7 @@ Joomla = window.Joomla || {}; const referenceDiff = reference.querySelector('#diff'); // Waiting until the reference has loaded before loading the target to avoid race conditions - if (referenceDiff) { - - } else { + if (!referenceDiff) { // Disable language field. reference.querySelector('#jform_language').setAttribute('disabled', ''); @@ -45,8 +43,7 @@ Joomla = window.Joomla || {}; }); targetIframe.addEventListener('load', () => { - - if (targetIframe.getAttribute('src') != '') { + if (targetIframe.getAttribute('src') !== '') { const target = targetIframe.contentDocument; // Update language field with the selected language and then disable it. From a866a1371f9fcc91d277a747f588df37dec5c542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 13:56:36 +0200 Subject: [PATCH 45/98] fix phpcs --- .../AssociationMasterController.php | 4 +-- .../Helper/AssociationsHelper.php | 23 +++++++++------- .../Helper/MasterAssociationsHelper.php | 27 +++++++++---------- .../Model/AssociationMasterModel.php | 12 ++++----- .../Model/AssociationsModel.php | 8 +++--- .../View/Association/HtmlView.php | 13 ++++----- .../View/Associations/HtmlView.php | 7 +++-- .../com_categories/Model/CategoryModel.php | 6 +++-- .../Service/HTML/AdministratorService.php | 9 ++++--- .../Service/HTML/AdministratorService.php | 11 +++++--- .../Service/HTML/AdministratorService.php | 11 +++++--- .../tmpl/compare/compareMaster.php | 2 +- .../components/com_menus/Model/ItemModel.php | 3 ++- .../com_menus/Service/HTML/Menus.php | 2 +- .../Service/HTML/AdministratorService.php | 13 +++++---- libraries/src/MVC/Model/AdminModel.php | 14 +++++----- .../system/languagefilter/languagefilter.php | 10 +++---- 17 files changed, 98 insertions(+), 77 deletions(-) diff --git a/administrator/components/com_associations/Controller/AssociationMasterController.php b/administrator/components/com_associations/Controller/AssociationMasterController.php index 14c48311dfa72..a4566309071c9 100644 --- a/administrator/components/com_associations/Controller/AssociationMasterController.php +++ b/administrator/components/com_associations/Controller/AssociationMasterController.php @@ -31,11 +31,11 @@ class AssociationMasterController extends BaseController public function update() { $targetId = $this->input->get('targetId', '', 'int'); - $masterId = $this->input->get('id', '' , 'int'); + $masterId = $this->input->get('id', '', 'int'); $itemtype = $this->input->get('itemtype', '', 'string'); $this->getModel('associationmaster')->update($targetId, $masterId, $itemtype); $this->setRedirect(Route::_('index.php?option=com_associations&view=associations', false)); } -} \ No newline at end of file +} diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index ba0375b8b2c4d..10a08484db437 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -219,7 +219,8 @@ private static function getExtensionRealName($extensionName) * * @since 3.7.0 */ - public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true, $assocLanguages = true, $assocState = 'all') + public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, + $addLink = true, $assocLanguages = true, $assocState = 'all') { // Get the associations list for this item. $items = self::getAssociationList($extensionName, $typeName, $itemId); @@ -234,6 +235,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId // Get the global master language, empty if not used $globalMasterLang = Associations::getGlobalMasterLanguage(); + // Check if versions are enabled $saveHistory = ComponentHelper::getParams($extensionName)->get('save_history', 0); $context = ($typeName === 'category') ? 'com_categories.item' : $extensionName . '.item'; @@ -252,7 +254,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $update = false; $masterInfo = ''; - if(!$globalMasterLang) + if (!$globalMasterLang) { // Don't do for the reference language. if ($langCode == $itemLanguage) @@ -352,7 +354,8 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId else { // When there is no associated master item, set it to target - if (!$masterId){ + if (!$masterId) + { $target = $globalMasterLang . ':0:add'; } @@ -364,7 +367,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId if ($associatedModifiedMaster < $lastModifiedMaster) { // Don't display not corresponding item - if($assocState !== 'all' && $assocState !== 'outdated'){ + if ($assocState !== 'all' && $assocState !== 'outdated'){ unset($items[$langCode]); continue; } @@ -374,9 +377,11 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; $update = true; - // When versions are disabled than the modified date is used for the master item. - // That means that when no changes were made and the master item has been saved the modified date has been changed. - // So the outdated state means in that case there might have been made changes and it is necessary to check manually and update the target. + /* + When versions are disabled than the modified date is used for the master item. + That means that when no changes were made and the master item has been saved the modified date has been changed. + So the outdated state means in that case there might have been made changes and it is necessary to check manually and update the target. + */ $masterInfo = $saveHistory ? $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') : $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); @@ -384,7 +389,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId else { // Don't display not corresponding item - if($assocState !== 'all' && $assocState !== 'up_to_date'){ + if ($assocState !== 'all' && $assocState !== 'up_to_date'){ unset($items[$langCode]); continue; } @@ -392,7 +397,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : ''; $masterInfo = $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); - // for item types that do not use modified date or versions like menu items + // For item types that do not use modified date or versions like menu items if (!$associatedModifiedMaster) { $masterInfo = ''; diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 44cc171cf23a5..d335eae130271 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -29,9 +29,9 @@ class MasterAssociationsHelper extends ContentHelper /** * Method to create a link for a child item that has no master item * - * @param string $globalMasterLang The global master language - * @param integer $itemId The item id - * @param string $itemType The item type + * @param string $globalMasterLang The global master language + * @param integer $itemId The item id + * @param string $itemType The item type * * @return string the link for the not associated master item */ @@ -51,10 +51,10 @@ public static function addNotAssociatedMasterLink($globalMasterLang, $itemId, $i $title = Text::_('JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC'); $url = self::getAssociationUrl($itemId, $globalMasterLang, $itemType); - $tooltip = '' . htmlspecialchars( $globalMasterLangInfos['title'], ENT_QUOTES, 'UTF-8') . '
      ' + $tooltip = '' . htmlspecialchars( $globalMasterLangInfos['title'],ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . $masterInfo; - $link = '' . $text . '' + $link = '' . $text . '' . ''; return $link; @@ -67,7 +67,6 @@ public static function addNotAssociatedMasterLink($globalMasterLang, $itemId, $i * @param string $context the association context * * @return array association with master dates - * */ public static function getMasterDates($associations, $context) { @@ -86,7 +85,7 @@ public static function getMasterDates($associations, $context) ->where($db->quoteName('id') . ' = ' . $db->quote($id)) ->where($db->quoteName('context') . ' = ' . $db->quote($context)); $db->setQuery($query); - $masterDates[$id] = $db->loadResult();; + $masterDates[$id] = $db->loadResult(); } return $masterDates; @@ -104,15 +103,15 @@ public static function getMasterDates($associations, $context) * * @return array master id and master dates for an associated item */ - public static function getMasterValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $old_key) { - + public static function getMasterValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $old_key) + { if ($masterId) { // For the master item if ($masterId === $id) { $masterIdValue = 0; - // set always the last modified date + // Set always the last modified date $masterDateValue = $masterModified ?? null; } @@ -154,19 +153,19 @@ public static function getMasterValues($id, $dataId, $masterId, $masterModified, */ public static function getMasterModifiedDate($masterId, $tableName, $typeAlias) { - // check if the content version is enabled + // Check if the content version is enabled $option = Factory::getApplication()->input->get('option'); $saveHistory = ComponentHelper::getParams($option)->get('save_history', 0); if ($masterId) { - // if versions are enabled get the save_data of the master item from history table + // If versions are enabled get the save_data of the master item from history table if ($saveHistory) { $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); $masterHistory = ContentHistoryHelper::getHistory($typeId, $masterId); - // latest saved date of the master item + // Latest saved date of the master item $masterModified = $masterHistory[0]->save_date; } else @@ -228,7 +227,7 @@ public static function setMasterAndChildInfos($itemId, $items, $key, $item, $glo } else { - // get association state of child when a master exists + // Get association state of child when a master exists if ($masterId && (array_key_exists($key, $assocMasterDates)) && (array_key_exists($masterId, $assocMasterDates))) { $associatedModifiedMaster = $assocMasterDates[$key]; diff --git a/administrator/components/com_associations/Model/AssociationMasterModel.php b/administrator/components/com_associations/Model/AssociationMasterModel.php index 5024de6f2f48c..425cdb9cbada3 100644 --- a/administrator/components/com_associations/Model/AssociationMasterModel.php +++ b/administrator/components/com_associations/Model/AssociationMasterModel.php @@ -25,16 +25,16 @@ class AssociationMasterModel extends BaseModel /** * Update the childs modified date of the master item from #__associations table. * - * @param integer $childId The id of the item that gets updated - * @param integer $masterId The associated master item of the child item - * @param string $itemtype The component item type + * @param integer $childId The id of the item that gets updated + * @param integer $masterId The associated master item of the child item + * @param string $itemtype The component item type * * @return boolean True on success. * * @since 4.0 */ - public function update($childId, $masterId, $itemtype) { - + public function update($childId, $masterId, $itemtype) + { list($extensionName, $typeName) = explode('.', $itemtype, 2); $context = ($typeName ==='category') @@ -69,4 +69,4 @@ public function update($childId, $masterId, $itemtype) { return true; } -} \ No newline at end of file +} diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 0226dc8459173..c7f86f546ab4c 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -467,9 +467,9 @@ protected function getListQuery() // Join over associations where id does not exists $query->where('((' . $db->quoteName('asso.id') . ' IS NULL )' - // or if we are on the child language and there is no master language + // Or if we are on the child language and there is no master language . ' OR ( ' . $db->quoteName('asso2.master_id') . ' = ' . $db->quote('-1') . ')' - // or a child of the master does not exist. + // Or a child of the master does not exist. . ' OR ( ' . $db->quoteName('asso.key') . ' IN (' . $assocQuery . ') AND ' . $db->quoteName('asso.master_id') . ' = ' . $db->quote('0') . ')' . ')'); @@ -481,7 +481,7 @@ protected function getListQuery() // If we are on the masterlanguage and we check the state of the children $query->where('((' . $db->quoteName('asso2.master_id') . ' = ' . $db->quoteName('asso.id') . ' AND ' . $db->quoteName('asso2.master_date') . ' < ' . $db->quoteName('asso.master_date') . ')' - // or we are on the child language and we check its state comparing to its master. + // Or we are on the child language and we check its state comparing to its master. . ' OR (' . $db->quoteName('asso.master_date') . ' < ' . $db->quoteName('asso2.master_date') . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.master_id') . '))'); } @@ -492,7 +492,7 @@ protected function getListQuery() // If we are on the masterlanguage and we check the state of the children $query->where('((' . $db->quoteName('asso2.master_id') . ' = ' . $db->quoteName('asso.id') . ' AND ' . $db->quoteName('asso2.master_date') . ' = ' . $db->quoteName('asso.master_date') . ')' - // or we are on the child language and we check its state comparing to its master. + // Or we are on the child language and we check its state comparing to its master. . ' OR (' . $db->quoteName('asso.master_date') . ' = ' . $db->quoteName('asso2.master_date') . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.master_id') . '))'); } diff --git a/administrator/components/com_associations/View/Association/HtmlView.php b/administrator/components/com_associations/View/Association/HtmlView.php index c62098a5eb543..4f27ecb6eac85 100644 --- a/administrator/components/com_associations/View/Association/HtmlView.php +++ b/administrator/components/com_associations/View/Association/HtmlView.php @@ -171,11 +171,11 @@ public function display($tpl = null) $task = $typeName . '.' . $this->targetAction; // The update layout can only be set when a global master language is used. - // get version ids of the master item, when versions are enabled. - if($this->getLayout() === 'update'){ + // Get version ids of the master item, when versions are enabled. + if ($this->getLayout() === 'update'){ $saveHistory = ComponentHelper::getParams($extensionName)->get('save_history', 0); - if($saveHistory) + if ($saveHistory) { $typeAlias = $typeName === 'category' ? $extensionName . '.' . $typeName : $reference['typeAlias']; $model = $this->getModel(); @@ -229,7 +229,7 @@ protected function addToolbar() $toolbar = Toolbar::getInstance('toolbar'); // The update layout can only be set when a global master language is used. - if($this->getLayout() === 'update') + if ($this->getLayout() === 'update') { // In the update view we can just save the target $toolbar->appendButton( @@ -238,9 +238,10 @@ protected function addToolbar() . Text::_('COM_ASSOCIATIONS_SAVE_AND_UPDATE_TARGET') . '', 'target' ); - // and when saving the target this button gets activated via js to update the master date for the child + // And when saving the target this button gets activated via js to update the master date for the child $toolbar->appendButton( - 'Custom', '', 'target' + 'Custom', '', 'target' ); } else diff --git a/administrator/components/com_associations/View/Associations/HtmlView.php b/administrator/components/com_associations/View/Associations/HtmlView.php index 55cea3d6c42a7..a2b97871fcee2 100644 --- a/administrator/components/com_associations/View/Associations/HtmlView.php +++ b/administrator/components/com_associations/View/Associations/HtmlView.php @@ -151,10 +151,10 @@ public function display($tpl = null) unset($this->activeFilters['language']); unset($this->activeFilters['assocstate']); - //Remove association state filter depending on global master language + // Remove association state filter depending on global master language $globalMasterLang = Associations::getGlobalMasterLanguage(); - if(!$globalMasterLang){ + if (!$globalMasterLang){ $this->filterForm->removeField('assocstate', 'filter'); } @@ -269,8 +269,7 @@ protected function addToolbar() ->text('COM_ASSOCIATIONS_PURGE') ->message((isset($this->extensionName) && isset($languageKey)) ? Text::plural('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT', (Text::_($this->extensionName) . ' > ' . Text::_($languageKey))) - : Text::_('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT') - ) + : Text::_('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT')) ->task('associations.purge'); ToolbarHelper::custom('associations.clean', 'refresh', 'refresh', 'COM_ASSOCIATIONS_DELETE_ORPHANS', false, false); ToolbarHelper::preferences('com_associations'); diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index c4616fbcd70d8..d5254b69dcb9f 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -699,8 +699,10 @@ public function save($data) { $masterIdAndDateValues = MasterAssociationsHelper::getMasterValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $oldKey); - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' - . $db->quote($masterIdAndDateValues[0]) . ',' . $db->quote($masterIdAndDateValues[1])); + $query->values( + ((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' + . $db->quote($masterIdAndDateValues[0]) . ',' . $db->quote($masterIdAndDateValues[1]) + ); } $db->setQuery($query); diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index 013478f878eec..e13d9903c4bc9 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -113,14 +113,17 @@ public function association($catid, $extension = 'com_content') continue; } - $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos($catid, $items, $key, $item, - $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); + $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos( + $catid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory + ); $labelClass = $classMasterInfoItems[0]; $masterInfo = $classMasterInfoItems[1]; $items = $classMasterInfoItems[2]; $needsUpdate = $classMasterInfoItems[3]; - $url = MasterAssociationsHelper::getAssociationUrl($item->id, $globalMasterLang, $extension . '.category', $item->lang_code, $key, $masterId, $needsUpdate); + $url = MasterAssociationsHelper::getAssociationUrl( + $item->id, $globalMasterLang, $extension . '.category', $item->lang_code, $key, $masterId, $needsUpdate + ); } $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index a1a9abe20a4c4..d368c43a5cbc0 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -116,14 +116,17 @@ public function association($contactid) continue; } - $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos($contactid, $items, $key, $item, - $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); + $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos( + $contactid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory + ); $labelClass = $classMasterInfoItems[0]; $masterInfo = $classMasterInfoItems[1]; $items = $classMasterInfoItems[2]; $needsUpdate = $classMasterInfoItems[3]; - $url = MasterAssociationsHelper::getAssociationUrl($item->id, $globalMasterLang, 'com_contact.contact', $item->lang_code, $key, $masterId, $needsUpdate); + $url = MasterAssociationsHelper::getAssociationUrl( + $item->id, $globalMasterLang, 'com_contact.contact', $item->lang_code, $key, $masterId, $needsUpdate + ); } $text = strtoupper($item->lang_sef); @@ -147,7 +150,7 @@ public function association($contactid) { $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $contactid, 'com_contact.contact'); - // add this on the top of the array + // Add this on the top of the array $items = array('master' => array('link' => $link)) + $items; } } diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index f7f36c6657b3d..08c02b84085d4 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -119,14 +119,17 @@ public function association($articleid) continue; } - $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos($articleid, $items, $key, $item, - $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); + $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos( + $articleid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory + ); $labelClass = $classMasterInfoItems[0]; $masterInfo = $classMasterInfoItems[1]; $items = $classMasterInfoItems[2]; $needsUpdate = $classMasterInfoItems[3]; - $url = MasterAssociationsHelper::getAssociationUrl($item->id, $globalMasterLang, 'com_content.article', $item->lang_code, $key, $masterId, $needsUpdate); + $url = MasterAssociationsHelper::getAssociationUrl( + $item->id, $globalMasterLang, 'com_content.article', $item->lang_code, $key, $masterId, $needsUpdate + ); } $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; @@ -150,7 +153,7 @@ public function association($articleid) { $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $articleid, 'com_content.article'); - // add this on the top of the array + // Add this on the top of the array $items = array('master' => array('link' => $link)) + $items; } } diff --git a/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php b/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php index 39e47096014cb..5083aa7d2354a 100644 --- a/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php +++ b/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php @@ -25,7 +25,7 @@ { $objLabel = $object2->title; } -else if (array_key_exists('name', $object2)){ +elseif (array_key_exists('name', $object2)){ $objLabel = $object2->name; } diff --git a/administrator/components/com_menus/Model/ItemModel.php b/administrator/components/com_menus/Model/ItemModel.php index d066648cdc6e9..34528cbe8f34c 100644 --- a/administrator/components/com_menus/Model/ItemModel.php +++ b/administrator/components/com_menus/Model/ItemModel.php @@ -1593,7 +1593,8 @@ public function save($data) // If there is no master item in this association, then reset the master id. // Otherwise, if the associated item is a master item, set its master id to 0, otherwise to the master Id. $masterIdValue = $masterId ? ($masterId === $id ? 0 : $masterId) : -1; - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' . $db->quote($masterIdValue) . ',' . $db->quote(null)); + $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) + . ',' . $db->quote($masterIdValue) . ',' . $db->quote(null)); } $db->setQuery($query); diff --git a/administrator/components/com_menus/Service/HTML/Menus.php b/administrator/components/com_menus/Service/HTML/Menus.php index 6888cf844945a..fd759aff51268 100644 --- a/administrator/components/com_menus/Service/HTML/Menus.php +++ b/administrator/components/com_menus/Service/HTML/Menus.php @@ -145,7 +145,7 @@ public function association($itemid) { $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $itemid, 'com_menus.item'); - // add this on the top of the array + // Add this on the top of the array $items = array('master' => array('link' => $link)) + $items; } } diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index a45311580afba..70a9b5925124d 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -114,19 +114,22 @@ public function association($newsfeedid) continue; } - $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos($newsfeedid, $items, $key, $item, - $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory); + $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos( + $newsfeedid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory + ); $labelClass = $classMasterInfoItems[0]; $masterInfo = $classMasterInfoItems[1]; $items = $classMasterInfoItems[2]; $needsUpdate = $classMasterInfoItems[3]; - $url = MasterAssociationsHelper::getAssociationUrl($item->id, $globalMasterLang, 'com_newsfeeds.newsfeed', $item->lang_code, $key, $masterId, $needsUpdate); + $url = MasterAssociationsHelper::getAssociationUrl( + $item->id, $globalMasterLang, 'com_newsfeeds.newsfeed', $item->lang_code, $key, $masterId, $needsUpdate + ); } $text = strtoupper($item->lang_sef); $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' - . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; + . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; $classes = 'badge ' . $labelClass; $item->link = '' . $text . '' @@ -145,7 +148,7 @@ public function association($newsfeedid) { $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $newsfeedid, 'com_newsfeeds.newsfeed'); - // add this on the top of the array + // Add this on the top of the array $items = array('master' => array('link' => $link)) + $items; } } diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index f4d8b1feee696..ef1968d184424 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -1321,7 +1321,7 @@ public function save($data) } // Get association params before they get deleted - if($associations) + if ($associations) { $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, $this->associationsContext); } @@ -1366,7 +1366,7 @@ public function save($data) $globalMasterLang = Associations::getGlobalMasterLanguage(); $masterId = $associations[$globalMasterLang] ?? ''; - // get id of the item that get saved + // Get id of the item that get saved $dataId = (int) $table->id; // Get the latest modified date of master item @@ -1380,8 +1380,10 @@ public function save($data) { $masterIdAndDateValues = MasterAssociationsHelper::getMasterValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $old_key); - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) - . ',' . $db->quote($masterIdAndDateValues[0]) . ',' . $db->quote($masterIdAndDateValues[1])); + $query->values( + ((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) + . ',' . $db->quote($masterIdAndDateValues[0]) . ',' . $db->quote($masterIdAndDateValues[1]) + ); } $db->setQuery($query); @@ -1670,8 +1672,8 @@ public function editAssociations($data) // If a global Master Language is set and the current item is a child item, then open the master item as reference and the child as target if ($globalMasterLang && !$isMaster) { - // if there is an associated master item change reference id. - if($data['associations'][$globalMasterLang]) + // If there is an associated master item change reference id. + if ($data['associations'][$globalMasterLang]) { $id = $data['associations'][$globalMasterLang]; $target = '&target=' . $data['language'] . '%3A' . $data['id'] . '%3Aedit'; diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index e381326bd277d..e0076b1caa7c1 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -1006,7 +1006,7 @@ public function onExtensionBeforeSave($context, $table) $params->global_master_language = ''; } - // check if there were changes for the master language + // Check if there were changes for the master language $this->hasMasterLangChanged = ($params->global_master_language === $this->params->get('global_master_language')) ? false : true; return $table->params = json_encode($params); @@ -1016,8 +1016,8 @@ public function onExtensionBeforeSave($context, $table) * After save extensions * Method is called when an extension has been saved. * - * @param string $context The extension - * @param JTable $table DataBase Table object + * @param string $context The extension + * @param JTable $table DataBase Table object * * @return void * @@ -1103,7 +1103,7 @@ private function _setMasterItem($language) $checkCategoryComponent = ''; $component = explode('.', $assocContext)[0]; - if($component === 'com_categories'){ + if ($component === 'com_categories'){ $fromTable = $db->quoteName('#__categories', 'e'); $modified = $db->quoteName('e.modified_time'); $checkCategoryComponent = $db->quoteName('e.extension'); @@ -1156,7 +1156,7 @@ private function _setMasterItem($language) $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); $masterHistory = ContentHistoryHelper::getHistory($typeId, $masterId); - // latest saved date of the master item + // Latest saved date of the master item $masterModified = $masterHistory[0]->save_date; } else From 0acf809764fc1b7654f2189fbfab9ae4dcb07fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 14:08:20 +0200 Subject: [PATCH 46/98] fix phpcs again --- .../com_associations/Helper/AssociationsHelper.php | 6 ++++-- .../com_associations/Helper/MasterAssociationsHelper.php | 3 ++- .../com_associations/View/Association/HtmlView.php | 3 ++- .../com_associations/View/Associations/HtmlView.php | 9 ++++++--- administrator/components/com_menus/Model/ItemModel.php | 6 ++++-- plugins/system/languagefilter/languagefilter.php | 3 ++- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 10a08484db437..1c02abfbabf98 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -367,7 +367,8 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId if ($associatedModifiedMaster < $lastModifiedMaster) { // Don't display not corresponding item - if ($assocState !== 'all' && $assocState !== 'outdated'){ + if ($assocState !== 'all' && $assocState !== 'outdated') + { unset($items[$langCode]); continue; } @@ -389,7 +390,8 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId else { // Don't display not corresponding item - if ($assocState !== 'all' && $assocState !== 'up_to_date'){ + if ($assocState !== 'all' && $assocState !== 'up_to_date') + { unset($items[$langCode]); continue; } diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index d335eae130271..755d5b35e0ba7 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -51,7 +51,7 @@ public static function addNotAssociatedMasterLink($globalMasterLang, $itemId, $i $title = Text::_('JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC'); $url = self::getAssociationUrl($itemId, $globalMasterLang, $itemType); - $tooltip = '' . htmlspecialchars( $globalMasterLangInfos['title'],ENT_QUOTES, 'UTF-8') . '
      ' + $tooltip = '' . htmlspecialchars($globalMasterLangInfos['title'], ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . $masterInfo; $link = '' . $text . '' @@ -111,6 +111,7 @@ public static function getMasterValues($id, $dataId, $masterId, $masterModified, if ($masterId === $id) { $masterIdValue = 0; + // Set always the last modified date $masterDateValue = $masterModified ?? null; } diff --git a/administrator/components/com_associations/View/Association/HtmlView.php b/administrator/components/com_associations/View/Association/HtmlView.php index 4f27ecb6eac85..6ea6778b1fc13 100644 --- a/administrator/components/com_associations/View/Association/HtmlView.php +++ b/administrator/components/com_associations/View/Association/HtmlView.php @@ -172,7 +172,8 @@ public function display($tpl = null) // The update layout can only be set when a global master language is used. // Get version ids of the master item, when versions are enabled. - if ($this->getLayout() === 'update'){ + if ($this->getLayout() === 'update') + { $saveHistory = ComponentHelper::getParams($extensionName)->get('save_history', 0); if ($saveHistory) diff --git a/administrator/components/com_associations/View/Associations/HtmlView.php b/administrator/components/com_associations/View/Associations/HtmlView.php index a2b97871fcee2..956a5877758b4 100644 --- a/administrator/components/com_associations/View/Associations/HtmlView.php +++ b/administrator/components/com_associations/View/Associations/HtmlView.php @@ -154,7 +154,8 @@ public function display($tpl = null) // Remove association state filter depending on global master language $globalMasterLang = Associations::getGlobalMasterLanguage(); - if (!$globalMasterLang){ + if (!$globalMasterLang) + { $this->filterForm->removeField('assocstate', 'filter'); } @@ -267,9 +268,11 @@ protected function addToolbar() { $toolbar->confirmButton('purge') ->text('COM_ASSOCIATIONS_PURGE') - ->message((isset($this->extensionName) && isset($languageKey)) + ->message( + (isset($this->extensionName) && isset($languageKey)) ? Text::plural('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT', (Text::_($this->extensionName) . ' > ' . Text::_($languageKey))) - : Text::_('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT')) + : Text::_('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT') + ) ->task('associations.purge'); ToolbarHelper::custom('associations.clean', 'refresh', 'refresh', 'COM_ASSOCIATIONS_DELETE_ORPHANS', false, false); ToolbarHelper::preferences('com_associations'); diff --git a/administrator/components/com_menus/Model/ItemModel.php b/administrator/components/com_menus/Model/ItemModel.php index 34528cbe8f34c..8731396b9cfee 100644 --- a/administrator/components/com_menus/Model/ItemModel.php +++ b/administrator/components/com_menus/Model/ItemModel.php @@ -1593,8 +1593,10 @@ public function save($data) // If there is no master item in this association, then reset the master id. // Otherwise, if the associated item is a master item, set its master id to 0, otherwise to the master Id. $masterIdValue = $masterId ? ($masterId === $id ? 0 : $masterId) : -1; - $query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) - . ',' . $db->quote($masterIdValue) . ',' . $db->quote(null)); + $query->values( + ((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) + . ',' . $db->quote($masterIdValue) . ',' . $db->quote(null) + ); } $db->setQuery($query); diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index e0076b1caa7c1..fcac8c5e6881a 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -1103,7 +1103,8 @@ private function _setMasterItem($language) $checkCategoryComponent = ''; $component = explode('.', $assocContext)[0]; - if ($component === 'com_categories'){ + if ($component === 'com_categories') + { $fromTable = $db->quoteName('#__categories', 'e'); $modified = $db->quoteName('e.modified_time'); $checkCategoryComponent = $db->quoteName('e.extension'); From 047bf748b77deaa73bfd55362294a222ddd53b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 14:34:39 +0200 Subject: [PATCH 47/98] fix hound --- build/media_source/com_associations/js/sidebysideupdate.es6.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/media_source/com_associations/js/sidebysideupdate.es6.js b/build/media_source/com_associations/js/sidebysideupdate.es6.js index 7c53059a80aac..eeed79df97a6c 100644 --- a/build/media_source/com_associations/js/sidebysideupdate.es6.js +++ b/build/media_source/com_associations/js/sidebysideupdate.es6.js @@ -19,7 +19,7 @@ Joomla = window.Joomla || {}; } else if (task === 'associationmaster.update') { Joomla.submitform(task); } else { - window.frames['target-association'].Joomla.submitbutton(document.getElementById('adminForm').getAttribute('data-associatedview') + '.apply'); + window.frames['target-association'].Joomla.submitbutton(`${document.getElementById('adminForm').getAttribute('data-associatedview')}, .apply`); document.getElementById('updateChild').click(); } }; From 55e46d1fbd91a5e0bceb0f15c0236802209a0064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:44:41 +0200 Subject: [PATCH 48/98] Update administrator/components/com_associations/forms/filter_associations.xml fix code alignment Co-Authored-By: Brian Teeman --- .../components/com_associations/forms/filter_associations.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_associations/forms/filter_associations.xml b/administrator/components/com_associations/forms/filter_associations.xml index 8d0f7b84ffa12..fdd625bd40f7b 100644 --- a/administrator/components/com_associations/forms/filter_associations.xml +++ b/administrator/components/com_associations/forms/filter_associations.xml @@ -24,7 +24,7 @@ label="COM_ASSOCIATIONS_FILTER_SELECT_ASSOCIATION_STATE" filtermode="selector" onchange="this.form.submit();" - > + > From eb2bdbb55167c2c097434329c7391ab297c9b5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:46:29 +0200 Subject: [PATCH 49/98] Update administrator/components/com_associations/Model/AssociationsModel.php fix error in comment Co-Authored-By: Brian Teeman --- .../components/com_associations/Model/AssociationsModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index c7f86f546ab4c..c08b480926189 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -465,7 +465,7 @@ protected function getListQuery() ->group($db->quoteName('key')) ->having('COUNT(*) < ' . $countLanguages); - // Join over associations where id does not exists + // Join over associations where id does not exist $query->where('((' . $db->quoteName('asso.id') . ' IS NULL )' // Or if we are on the child language and there is no master language . ' OR ( ' . $db->quoteName('asso2.master_id') . ' = ' . $db->quote('-1') . ')' From 285944f4f5e164b6529b678e1c5f0c4d3bf5f8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:47:44 +0200 Subject: [PATCH 50/98] Update administrator/components/com_associations/Model/AssociationsModel.php fix grammar error in comment Co-Authored-By: Brian Teeman --- .../components/com_associations/Model/AssociationsModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index c08b480926189..35169e397b83e 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -82,7 +82,7 @@ protected function populateState($ordering = 'ordering', $direction = 'asc') $forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd'); $forcedItemType = $app->input->get('forcedItemType', '', 'string'); - // Set language select box to default site language or if set to the master language as default. + // Set language select box to default site language or if set to, to the master language as default. $globalMasterLang = Associations::getGlobalMasterLanguage(); $langParam = ComponentHelper::getParams('com_languages'); From 3ac180060bf0e6be0e6e970d6775d88288fc3dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:48:14 +0200 Subject: [PATCH 51/98] Update administrator/components/com_associations/Helper/MasterAssociationsHelper.php fix type error in comment Co-Authored-By: Brian Teeman --- .../com_associations/Helper/MasterAssociationsHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 755d5b35e0ba7..4f33253db5f19 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -160,7 +160,7 @@ public static function getMasterModifiedDate($masterId, $tableName, $typeAlias) if ($masterId) { - // If versions are enabled get the save_data of the master item from history table + // If versions are enabled get the save_date of the master item from history table if ($saveHistory) { $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); From 6e30b12c2370dbc2d9acb66963c7716237eac0c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:48:36 +0200 Subject: [PATCH 52/98] Update administrator/components/com_associations/Helper/MasterAssociationsHelper.php fix grammar error in comment Co-Authored-By: Brian Teeman --- .../com_associations/Helper/MasterAssociationsHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 4f33253db5f19..f159f4fd177a1 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -144,7 +144,7 @@ public static function getMasterValues($id, $dataId, $masterId, $masterModified, } /** - * Method to get the latest modified date of an master item + * Method to get the latest modified date of a master item * * @param integer $masterId Id of the associated master item * @param string $tableName The name of the table. From ad19dc30019ad44546bc86969ec1eab420736e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:49:02 +0200 Subject: [PATCH 53/98] Update administrator/components/com_associations/Helper/AssociationsHelper.php fix type error in comment Co-Authored-By: Brian Teeman --- .../components/com_associations/Helper/AssociationsHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 1c02abfbabf98..0e727bf449d89 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -379,7 +379,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $update = true; /* - When versions are disabled than the modified date is used for the master item. + When versions are disabled then the modified date is used for the master item. That means that when no changes were made and the master item has been saved the modified date has been changed. So the outdated state means in that case there might have been made changes and it is necessary to check manually and update the target. */ From 42a39b2d44d37af1b7444376c1d1565f1086b8c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:50:00 +0200 Subject: [PATCH 54/98] Update administrator/components/com_categories/Model/CategoryModel.php fix grammar error in comment Co-Authored-By: Brian Teeman --- administrator/components/com_categories/Model/CategoryModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index d5254b69dcb9f..79ca6c608610f 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -680,7 +680,7 @@ public function save($data) if (count($associations) > 1) { - // If there is an association item with the globalMasterLanguage, then get his id + // If there is an association item with the globalMasterLanguage, then get its id $globalMasterLang = Associations::getGlobalMasterLanguage(); $masterId = $associations[$globalMasterLang] ?? ''; From ba57d955e0d123cdb8f5120b53e053754b85cd01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:50:30 +0200 Subject: [PATCH 55/98] Update administrator/components/com_categories/Service/HTML/AdministratorService.php fix grammar error in comment Co-Authored-By: Brian Teeman --- .../com_categories/Service/HTML/AdministratorService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index e13d9903c4bc9..59450a5bb5ec5 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -88,7 +88,7 @@ public function association($catid, $extension = 'com_content') ? true : false; - // Check if there is a master item in the association and get his id if so. + // Check if there is a master item in the association and get its id if so. $masterId = array_key_exists($globalMasterLang, $associations) ? $associations[$globalMasterLang] : ''; From 190ab67a423823204685908988cbf8b2b15760fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:50:54 +0200 Subject: [PATCH 56/98] Update administrator/components/com_contact/Service/HTML/AdministratorService.php fix grammar error in comment Co-Authored-By: Brian Teeman --- .../com_contact/Service/HTML/AdministratorService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index d368c43a5cbc0..a8104077c5e4f 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -91,7 +91,7 @@ public function association($contactid) ? true : false; - // Check if there is a master item in the association and get his id if so. + // Check if there is a master item in the association and get its id if so. $masterId = array_key_exists($globalMasterLang, $associations) ? $associations[$globalMasterLang] : ''; From 3918c305000eb278a7d82fbae79704b6e0fc3c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:51:45 +0200 Subject: [PATCH 57/98] Update administrator/components/com_content/Service/HTML/AdministratorService.php fix grammar error Co-Authored-By: Brian Teeman --- .../com_content/Service/HTML/AdministratorService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index 08c02b84085d4..733ed408eb07f 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -93,7 +93,7 @@ public function association($articleid) ? true : false; - // Check if there is a master item in the association and get his id if so + // Check if there is a master item in the association and get its id if so $masterId = array_key_exists($globalMasterLang, $associations) ? $associations[$globalMasterLang] : ''; From ef1eb55a51263b899e5174eb254c796b65fb72b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:55:19 +0200 Subject: [PATCH 58/98] Update administrator/components/com_menus/Service/HTML/Menus.php fix grammar error Co-Authored-By: Brian Teeman --- administrator/components/com_menus/Service/HTML/Menus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_menus/Service/HTML/Menus.php b/administrator/components/com_menus/Service/HTML/Menus.php index fd759aff51268..17d065e41b039 100644 --- a/administrator/components/com_menus/Service/HTML/Menus.php +++ b/administrator/components/com_menus/Service/HTML/Menus.php @@ -86,7 +86,7 @@ public function association($itemid) ? true : false; - // Check if there is a master item in the association and get his id if so + // Check if there is a master item in the association and get its id if so $masterId = array_key_exists($globalMasterLang, $associations) ? $associations[$globalMasterLang] : ''; From 5052e701f7eebee58f3c49c06bd34db0029fe672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:55:38 +0200 Subject: [PATCH 59/98] Update administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php fix grammar error Co-Authored-By: Brian Teeman --- .../com_newsfeeds/Service/HTML/AdministratorService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index 70a9b5925124d..ee2ea53b9cec6 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -89,7 +89,7 @@ public function association($newsfeedid) ? true : false; - // Check if there is a master item in the association and get his id if so. + // Check if there is a master item in the association and get its id if so. $masterId = array_key_exists($globalMasterLang, $associations) ? $associations[$globalMasterLang] : ''; From dc4404013307399c1ae78c178aeec42f20408f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:57:34 +0200 Subject: [PATCH 60/98] Update administrator/language/en-GB/en-GB.com_associations.ini fix error in language string Co-Authored-By: Brian Teeman --- administrator/language/en-GB/en-GB.com_associations.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index 27c2ee9e897fb..d708b259ef743 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -53,6 +53,6 @@ COM_ASSOCIATIONS_TITLE="Associations" COM_ASSOCIATIONS_TITLE_EDIT="Multilingual Associations: Edit Associations (%1s > %2s)" COM_ASSOCIATIONS_TITLE_LIST="Multilingual Associations (%1s > %2s)" COM_ASSOCIATIONS_TITLE_LIST_SELECT="Multilingual Associations: Select Item Type and Language" -COM_ASSOCIATIONS_UPDATE_ASSOCIATION="Update association" +COM_ASSOCIATIONS_UPDATE_ASSOCIATION="Update Association" COM_ASSOCIATIONS_XML_DESCRIPTION="Improved multilingual content management component" COM_ASSOCIATIONS_YOU_ARE_NOT_ALLOWED_TO_CHECKIN_THIS_ITEM="You can't check in this item" From 3215e64b14d16ff9bad6ba16e190e1dee5029933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 15:04:39 +0200 Subject: [PATCH 61/98] Update installation/src/Model/LanguagesModel.php fix grammar error Co-Authored-By: Brian Teeman --- installation/src/Model/LanguagesModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/src/Model/LanguagesModel.php b/installation/src/Model/LanguagesModel.php index c2c065ab4809a..0113973332323 100644 --- a/installation/src/Model/LanguagesModel.php +++ b/installation/src/Model/LanguagesModel.php @@ -1411,7 +1411,7 @@ public function addAssociations($groupedAssociations) foreach ($groupedAssociations as $context => $associations) { - // If there is an association item with the globalMasterLanguage, get his id. + // If there is an association item with the globalMasterLanguage, get its id. $masterId = $associations[$globalMasterLang] ?? ''; $key = md5(json_encode($associations)); $query = $db->getQuery(true) From 3c182aed78c5c35edb7358d3f07a3c9d7f46f82a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 15:05:04 +0200 Subject: [PATCH 62/98] Update libraries/src/MVC/Model/AdminModel.php fix grammar error Co-Authored-By: Brian Teeman --- libraries/src/MVC/Model/AdminModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index ef1968d184424..24a3ab3dc0a53 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -1362,7 +1362,7 @@ public function save($data) if (count($associations) > 1) { - // If there is an association item with the globalMasterLanguage, then get his id + // If there is an association item with the globalMasterLanguage, then get its id $globalMasterLang = Associations::getGlobalMasterLanguage(); $masterId = $associations[$globalMasterLang] ?? ''; From 88ddb2a6d67793da236446c3baa1236b58cb6164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 15:05:20 +0200 Subject: [PATCH 63/98] Update plugins/system/languagefilter/languagefilter.xml fix code alignment Co-Authored-By: Brian Teeman --- plugins/system/languagefilter/languagefilter.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/languagefilter/languagefilter.xml b/plugins/system/languagefilter/languagefilter.xml index 33a7a810ff633..4f33ecd7639d4 100644 --- a/plugins/system/languagefilter/languagefilter.xml +++ b/plugins/system/languagefilter/languagefilter.xml @@ -69,7 +69,7 @@ class="switcher" default="0" showon="item_associations:1" - > + > From 952d7fb9aa926832a3ec1f41869eb6cccb599e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 15:14:52 +0200 Subject: [PATCH 64/98] Update administrator/language/en-GB/en-GB.ini fix using correct word Co-Authored-By: Brian Teeman --- administrator/language/en-GB/en-GB.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/language/en-GB/en-GB.ini b/administrator/language/en-GB/en-GB.ini index 4c91a7af5db79..b5f4ecd99bd80 100644 --- a/administrator/language/en-GB/en-GB.ini +++ b/administrator/language/en-GB/en-GB.ini @@ -291,7 +291,7 @@ JGLOBAL_ASSOCIATIONS_PROPAGATE_TIP="Propagates this item's existing associations JGLOBAL_ASSOCIATIONS_RESET_WARNING="The language has been changed. If you save this item again it will reset the available associations. If this was not intended, close the item." JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC="This item might be outdated with the master article." JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC="There is no association for the master language." -JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC="This item is outdated with the master item." +JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC="This item is out of date with the master item." JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC="This item is up-to-date with the master item." JGLOBAL_AUTH_ACCESS_DENIED="Access Denied" JGLOBAL_AUTH_ACCESS_GRANTED="Access Granted" From 393ed647fe52a29a409bc040cdaa46e6a3f37cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 15:15:09 +0200 Subject: [PATCH 65/98] Update administrator/language/en-GB/en-GB.ini fix using correct word Co-Authored-By: Brian Teeman --- administrator/language/en-GB/en-GB.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/language/en-GB/en-GB.ini b/administrator/language/en-GB/en-GB.ini index b5f4ecd99bd80..8a7a3bdb3c1f7 100644 --- a/administrator/language/en-GB/en-GB.ini +++ b/administrator/language/en-GB/en-GB.ini @@ -289,7 +289,7 @@ JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE="No associations exist to propagate. JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME="Associations have been set for: %s" JGLOBAL_ASSOCIATIONS_PROPAGATE_TIP="Propagates this item's existing associations." JGLOBAL_ASSOCIATIONS_RESET_WARNING="The language has been changed. If you save this item again it will reset the available associations. If this was not intended, close the item." -JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC="This item might be outdated with the master article." +JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC="This item might be out of date with the master article." JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC="There is no association for the master language." JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC="This item is out of date with the master item." JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC="This item is up-to-date with the master item." From 588ee55aeefdd68d2e7e50216514d3bd08affbeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 15:24:41 +0200 Subject: [PATCH 66/98] fix alpha ordering in 'use' and removed commented out code line --- .../com_associations/Field/ContentmasterlanguageField.php | 2 +- .../components/com_associations/tmpl/association/update.php | 1 - .../system/languagefilter/Field/ContentsitelanguageField.php | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/administrator/components/com_associations/Field/ContentmasterlanguageField.php b/administrator/components/com_associations/Field/ContentmasterlanguageField.php index daa598dc5cd1a..1f907a9c2b21d 100644 --- a/administrator/components/com_associations/Field/ContentmasterlanguageField.php +++ b/administrator/components/com_associations/Field/ContentmasterlanguageField.php @@ -14,8 +14,8 @@ use Joomla\CMS\Form\Field\ContentlanguageField; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Associations; -use Joomla\CMS\Language\Text; use Joomla\CMS\Language\LanguageHelper; +use Joomla\CMS\Language\Text; use Joomla\Registry\Registry; diff --git a/administrator/components/com_associations/tmpl/association/update.php b/administrator/components/com_associations/tmpl/association/update.php index 9d0b932a5ec2b..820829c9dc344 100644 --- a/administrator/components/com_associations/tmpl/association/update.php +++ b/administrator/components/com_associations/tmpl/association/update.php @@ -19,7 +19,6 @@ HTMLHelper::_('jquery.framework'); HTMLHelper::_('script', 'com_associations/sidebysideupdate.js', ['version' => 'auto', 'relative' => true]); -//HTMLHelper::_('script', 'com_associations/sidebyside.js', ['version' => 'auto', 'relative' => true]); HTMLHelper::_('stylesheet', 'com_associations/sidebyside.css', ['version' => 'auto', 'relative' => true]); $options = array( diff --git a/plugins/system/languagefilter/Field/ContentsitelanguageField.php b/plugins/system/languagefilter/Field/ContentsitelanguageField.php index 8355fefc8c092..0835815ee8a72 100644 --- a/plugins/system/languagefilter/Field/ContentsitelanguageField.php +++ b/plugins/system/languagefilter/Field/ContentsitelanguageField.php @@ -14,8 +14,8 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Form\Field\ContentlanguageField; use Joomla\CMS\HTML\HTMLHelper; -use Joomla\CMS\Language\Text; use Joomla\CMS\Language\LanguageHelper; +use Joomla\CMS\Language\Text; /** From 3951117e552e4082d2b1f306ee3d3135cb0fae6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 15:41:52 +0200 Subject: [PATCH 67/98] remove fieldset wrapping table --- .../tmpl/compare/compareMaster.php | 88 +++++++++---------- 1 file changed, 43 insertions(+), 45 deletions(-) diff --git a/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php b/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php index 5083aa7d2354a..2af62b6ddd08c 100644 --- a/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php +++ b/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php @@ -21,11 +21,12 @@ $object2 = $version2->data; $objLabel = ''; -if(array_key_exists('title', $object2)) +if (array_key_exists('title', $object2)) { $objLabel = $object2->title; } -elseif (array_key_exists('name', $object2)){ +elseif (array_key_exists('name', $object2)) +{ $objLabel = $object2->name; } @@ -52,48 +53,45 @@
      -
      - - - - - - - - - $value) : ?> - value != $object2->$name->value) : ?> - - value)) : ?> - - value as $subName => $subValue) : ?> - $name->value->$subName->value ?? ''; ?> - value || $newSubValue) : ?> - value != $newSubValue) : ?> - - - - - - - +
      - label; ?> -
      label; ?>
      + + + + + + + + $value) : ?> + value != $object2->$name->value) : ?> + + value)) : ?> + + value as $subName => $subValue) : ?> + $name->value->$subName->value ?? ''; ?> + value || $newSubValue) : ?> + value != $newSubValue) : ?> + + + + + + - - - - - $name->value = is_object($object2->$name->value) ? json_encode($object2->$name->value) : $object2->$name->value; ?> - - - - + + + + + + $name->value = is_object($object2->$name->value) ? json_encode($object2->$name->value) : $object2->$name->value; ?> + + - - -
      + label; ?> +
      label; ?>
      - label; ?> -
      + label; ?> +
      - -
      + + + + + From f6ba2eef2e2369da67cb5c2b2b806888ece5cdb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 16:56:05 +0200 Subject: [PATCH 68/98] Update plugins/sampledata/multilang/multilang.php fix typo Co-Authored-By: SharkyKZ --- plugins/sampledata/multilang/multilang.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sampledata/multilang/multilang.php b/plugins/sampledata/multilang/multilang.php index 9f3dc4a162885..3c114aefc8be0 100644 --- a/plugins/sampledata/multilang/multilang.php +++ b/plugins/sampledata/multilang/multilang.php @@ -518,7 +518,7 @@ private function enablePlugin($pluginName) . '"remove_default_prefix":"0",' . '"lang_cookie":"0",' . '"alternate_meta":"1",' - . '"user_master_language":"0",' + . '"use_master_language":"0",' . '"global_master_language":""' . '}'; $query From f6f3e9d5c255bd99fb2e317c5adb87ef66b35109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 18:19:41 +0200 Subject: [PATCH 69/98] fix correct typeAlias for categories --- .../com_associations/Helper/MasterAssociationsHelper.php | 4 ++-- .../components/com_categories/Model/CategoryModel.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index f159f4fd177a1..d844754fbcb07 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -155,8 +155,8 @@ public static function getMasterValues($id, $dataId, $masterId, $masterModified, public static function getMasterModifiedDate($masterId, $tableName, $typeAlias) { // Check if the content version is enabled - $option = Factory::getApplication()->input->get('option'); - $saveHistory = ComponentHelper::getParams($option)->get('save_history', 0); + $aliasParts = explode('.', $typeAlias); + $saveHistory = ComponentHelper::getParams($aliasParts[0])->get('save_history', 0); if ($masterId) { diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index 79ca6c608610f..93f7080b653fb 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -688,7 +688,7 @@ public function save($data) $dataId = (int) $table->id; // Get the latest modified date of master item - $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName(), $table->typeAlias); + $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName(), $table->extension . '.category'); // Adding new association for these items $key = md5(json_encode($associations)); From 439c6ad9f82a08a5f474e99c1534bac3b06e5206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 18:35:24 +0200 Subject: [PATCH 70/98] get modified table name from contentType table To avoid setting the correct column name for modified date manually, get the name from the content type table. --- .../Helper/MasterAssociationsHelper.php | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index d844754fbcb07..43438892b85fc 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -155,15 +155,27 @@ public static function getMasterValues($id, $dataId, $masterId, $masterModified, public static function getMasterModifiedDate($masterId, $tableName, $typeAlias) { // Check if the content version is enabled - $aliasParts = explode('.', $typeAlias); - $saveHistory = ComponentHelper::getParams($aliasParts[0])->get('save_history', 0); + $aliasParts = explode('.', $typeAlias); + $saveHistory = ComponentHelper::getParams($aliasParts[0])->get('save_history', 0); + $contentTypeTable = Table::getInstance('ContentType'); + $contentTypeTblName = $contentTypeTable->getTableName(); + $typeId = $contentTypeTable->getTypeId($typeAlias); + + $db = Factory::getDbo(); + $fieldMapsQuery = $db->getQuery(true) + ->select($db->quoteName('field_mappings')) + ->from($db->quoteName($contentTypeTblName)) + ->where($db->quoteName('type_id') . ' = ' . $db->quote($typeId)); + $db->setQuery($fieldMapsQuery); + $fieldMaps = $db->loadResult(); + + $modifiedColumn = json_decode($fieldMaps)->common->core_modified_time; if ($masterId) { // If versions are enabled get the save_date of the master item from history table if ($saveHistory) { - $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); $masterHistory = ContentHistoryHelper::getHistory($typeId, $masterId); // Latest saved date of the master item @@ -171,17 +183,6 @@ public static function getMasterModifiedDate($masterId, $tableName, $typeAlias) } else { - $db = Factory::getDbo(); - - if ($tableName === '#__categories') - { - $modifiedColumn = 'modified_time'; - } - else - { - $modifiedColumn = 'modified'; - } - $masterDateQuery = $db->getQuery(true) ->select($db->quoteName($modifiedColumn)) ->from($db->quoteName($tableName)) From 8f97cc0d7e58e26d88324d673ef2dc2eff2dc930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 18:39:41 +0200 Subject: [PATCH 71/98] Update plugins/system/languagefilter/languagefilter.xml Co-Authored-By: SharkyKZ --- plugins/system/languagefilter/languagefilter.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/system/languagefilter/languagefilter.xml b/plugins/system/languagefilter/languagefilter.xml index 4f33ecd7639d4..ae0708707ad88 100644 --- a/plugins/system/languagefilter/languagefilter.xml +++ b/plugins/system/languagefilter/languagefilter.xml @@ -68,6 +68,7 @@ description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_DESC" class="switcher" default="0" + filter="integer" showon="item_associations:1" > From a7c72db82de9ceb27aa9e3379108fecc9ce7dd3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 18:39:54 +0200 Subject: [PATCH 72/98] Update plugins/sampledata/multilang/multilang.php Co-Authored-By: SharkyKZ --- plugins/sampledata/multilang/multilang.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sampledata/multilang/multilang.php b/plugins/sampledata/multilang/multilang.php index 3c114aefc8be0..23b9616a15617 100644 --- a/plugins/sampledata/multilang/multilang.php +++ b/plugins/sampledata/multilang/multilang.php @@ -518,7 +518,7 @@ private function enablePlugin($pluginName) . '"remove_default_prefix":"0",' . '"lang_cookie":"0",' . '"alternate_meta":"1",' - . '"use_master_language":"0",' + . '"use_master_language":0,' . '"global_master_language":""' . '}'; $query From da88da9b7fe6ed025b7af8ae7c9018d9f44f2580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Tue, 2 Jul 2019 18:40:11 +0200 Subject: [PATCH 73/98] Update plugins/system/languagefilter/languagefilter.php Co-Authored-By: SharkyKZ --- plugins/system/languagefilter/languagefilter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index fcac8c5e6881a..1effab195335f 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -995,7 +995,7 @@ public function onExtensionBeforeSave($context, $table) // If the plugin and the parameter item_associations are enabled then set the correct value for the global master language. if ($pluginStatus && $itemAssocStatus) { - $params->global_master_language = ($params->use_master_language === '1') + $params->global_master_language = ($params->use_master_language === 1) ? $params->global_master_language : ''; } From 01f9cd825c9644d30431a81a3392b4050d3ad322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 19:03:13 +0200 Subject: [PATCH 74/98] fix wrong uppercase filename Since uppercase letters are not supported in layouts, the file name is changed to lowercase. --- .../components/com_associations/tmpl/association/update.php | 2 +- .../tmpl/compare/{compareMaster.php => comparemaster.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename administrator/components/com_contenthistory/tmpl/compare/{compareMaster.php => comparemaster.php} (100%) diff --git a/administrator/components/com_associations/tmpl/association/update.php b/administrator/components/com_associations/tmpl/association/update.php index 820829c9dc344..74e5720417337 100644 --- a/administrator/components/com_associations/tmpl/association/update.php +++ b/administrator/components/com_associations/tmpl/association/update.php @@ -35,7 +35,7 @@ referenceVersionIdNew)) : ?>

      diff --git a/administrator/components/com_contenthistory/tmpl/compare/compareMaster.php b/administrator/components/com_contenthistory/tmpl/compare/comparemaster.php similarity index 100% rename from administrator/components/com_contenthistory/tmpl/compare/compareMaster.php rename to administrator/components/com_contenthistory/tmpl/compare/comparemaster.php From 5c321cb6c69a6d991aecceb55a7a8efc4a3ed549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Tue, 2 Jul 2019 21:04:46 +0200 Subject: [PATCH 75/98] change type of master_date to date and add update sqls The master_date type changed from text to date as it only will contain dates. For this the null-values were adjusted. Also add the update sqls for the new columns. --- .../com_associations/Helper/MasterAssociationsHelper.php | 6 +++--- .../components/com_categories/Model/CategoryModel.php | 4 +++- administrator/components/com_menus/Model/ItemModel.php | 2 +- installation/sql/mysql/joomla.sql | 2 +- installation/sql/postgresql/joomla.sql | 2 +- installation/src/Model/LanguagesModel.php | 2 +- libraries/src/MVC/Model/AdminModel.php | 4 +++- plugins/sampledata/multilang/multilang.php | 2 +- plugins/system/languagefilter/languagefilter.php | 8 ++++---- 9 files changed, 18 insertions(+), 14 deletions(-) diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 43438892b85fc..305f734669731 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -113,7 +113,7 @@ public static function getMasterValues($id, $dataId, $masterId, $masterModified, $masterIdValue = 0; // Set always the last modified date - $masterDateValue = $masterModified ?? null; + $masterDateValue = $masterModified ?? 'NULL'; } // For the children @@ -129,7 +129,7 @@ public static function getMasterValues($id, $dataId, $masterId, $masterModified, if (!$old_key && ($dataId === $id)) { // Add modified date from master to new associated item - $masterDateValue = $masterModified ?? null; + $masterDateValue = $masterModified ?? 'NULL'; } } } @@ -137,7 +137,7 @@ public static function getMasterValues($id, $dataId, $masterId, $masterModified, { // Default values when there is no associated master item. $masterIdValue = -1; - $masterDateValue = null; + $masterDateValue = 'NULL'; } return [(int) $masterIdValue, $masterDateValue]; diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index 93f7080b653fb..63f9d2001b00f 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -698,10 +698,12 @@ public function save($data) foreach ($associations as $id) { $masterIdAndDateValues = MasterAssociationsHelper::getMasterValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $oldKey); + $masterIdValue = $masterIdAndDateValues[0]; + $masterDateValue = $masterIdAndDateValues[1] === 'NULL' ? $masterIdAndDateValues[1] : $db->quote($masterIdAndDateValues[1]); $query->values( ((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' - . $db->quote($masterIdAndDateValues[0]) . ',' . $db->quote($masterIdAndDateValues[1]) + . $db->quote($masterIdValue) . ',' . $masterDateValue ); } diff --git a/administrator/components/com_menus/Model/ItemModel.php b/administrator/components/com_menus/Model/ItemModel.php index 8731396b9cfee..0ecbe7d8e24f6 100644 --- a/administrator/components/com_menus/Model/ItemModel.php +++ b/administrator/components/com_menus/Model/ItemModel.php @@ -1595,7 +1595,7 @@ public function save($data) $masterIdValue = $masterId ? ($masterId === $id ? 0 : $masterId) : -1; $query->values( ((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) - . ',' . $db->quote($masterIdValue) . ',' . $db->quote(null) + . ',' . $db->quote($masterIdValue) . ', NULL' ); } diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index b0d19d39428d5..e0721e8b1e47c 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -108,7 +108,7 @@ CREATE TABLE IF NOT EXISTS `#__associations` ( `context` varchar(50) NOT NULL COMMENT 'The context of the associated item.', `key` char(32) NOT NULL COMMENT 'The key for the association computed from an md5 on associated ids.', `master_id` int(11) NOT NULL DEFAULT -1 COMMENT 'The master item of an association.', - `master_date` text COMMENT 'The save or modified date of the master item.', + `master_date` datetime COMMENT 'The save or modified date of the master item.', PRIMARY KEY (`context`,`id`), KEY `idx_key` (`key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index 3440b3cdf134c..ce069575e55fe 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -112,7 +112,7 @@ CREATE TABLE IF NOT EXISTS "#__associations" ( "context" varchar(50) NOT NULL, "key" char(32) NOT NULL, "master_id" integer DEFAULT -1 NOT NULL, - "master_date" text, + "master_date" timestamp without time zone, CONSTRAINT "#__associations_idx_context_id" PRIMARY KEY ("context", "id") ); CREATE INDEX "#__associations_idx_key" ON "#__associations" ("key"); diff --git a/installation/src/Model/LanguagesModel.php b/installation/src/Model/LanguagesModel.php index 0113973332323..dace53b0606f5 100644 --- a/installation/src/Model/LanguagesModel.php +++ b/installation/src/Model/LanguagesModel.php @@ -1422,7 +1422,7 @@ public function addAssociations($groupedAssociations) // If there is no master item in this association, then reset the master_id to -1 // Otherwise, if the association item is a master item set the master_id to 0, otherwise to the masterId. $masterIdValue = $masterId ? ($masterId === $id ? 0 : $masterId) : -1; - $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($masterIdValue) . ',' . $db->quote('')); + $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($masterIdValue) . ', NULL'); } $db->setQuery($query); diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 24a3ab3dc0a53..5191d31f3dce3 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -1379,10 +1379,12 @@ public function save($data) foreach ($associations as $id) { $masterIdAndDateValues = MasterAssociationsHelper::getMasterValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $old_key); + $masterIdValue = $masterIdAndDateValues[0]; + $masterDateValue = $masterIdAndDateValues[1] === 'NULL' ? $masterIdAndDateValues[1] : $db->quote($masterIdAndDateValues[1]); $query->values( ((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) - . ',' . $db->quote($masterIdAndDateValues[0]) . ',' . $db->quote($masterIdAndDateValues[1]) + . ',' . $db->quote($masterIdValue) . ',' . $masterDateValue ); } diff --git a/plugins/sampledata/multilang/multilang.php b/plugins/sampledata/multilang/multilang.php index 23b9616a15617..b0124f5a9422a 100644 --- a/plugins/sampledata/multilang/multilang.php +++ b/plugins/sampledata/multilang/multilang.php @@ -909,7 +909,7 @@ private function addAssociations($groupedAssociations) foreach ($associations as $language => $id) { - $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote('-1') . ',' . $db->quote('')); + $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote('-1') . ', NULL'); } $db->setQuery($query); diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index 1effab195335f..58f737f067577 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -1067,7 +1067,7 @@ private function _setMasterItem($language) $resetQuery = $db->getQuery(true) ->update($db->quoteName('#__associations')) ->set($db->quoteName('master_id') . ' = ' . -1) - ->set($db->quoteName('master_date') . ' = ' . $db->quote(null)); + ->set($db->quoteName('master_date') . ' = NULL'); $db->setQuery($resetQuery); try @@ -1170,14 +1170,14 @@ private function _setMasterItem($language) } } - $masterModified = $modified ? $masterModified : null; + $masterModified = $modified ? $db->quote($masterModified) : 'NULL'; $masterId = $masterId ?? -1; // Set the id and the modified date of the master item. $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) ->set($db->quoteName('master_id') . ' = ' . $db->quote(0)) - ->set($db->quoteName('master_date') . ' = ' . $db->quote($masterModified)) + ->set($db->quoteName('master_date') . ' = ' . $masterModified) ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)) ->where($db->quoteName('key') . ' = ' . $db->quote($value)) ->where($db->quoteName('context') . ' = ' . $db->quote($assocContext)); @@ -1196,7 +1196,7 @@ private function _setMasterItem($language) $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) ->set($db->quoteName('master_id') . ' = ' . $db->quote($masterId)) - ->set($db->quoteName('master_date') . ' = ' . $db->quote($masterModified)) + ->set($db->quoteName('master_date') . ' = ' . $masterModified) ->where($db->quoteName('id') . ' <> ' . $db->quote($masterId)) ->where($db->quoteName('key') . ' = ' . $db->quote($value)) ->where($db->quoteName('context') . ' = ' . $db->quote($assocContext)); From ab0e2bd70b6ea035b329cd3044a908fc93c8b883 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Tue, 2 Jul 2019 21:15:22 +0200 Subject: [PATCH 76/98] Add schema updates to pr 25403 --- .../com_admin/sql/updates/mysql/4.0.0-2019-07-02.sql | 2 ++ .../com_admin/sql/updates/postgresql/4.0.0-2019-07-02.sql | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-07-02.sql create mode 100644 administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-07-02.sql diff --git a/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-07-02.sql b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-07-02.sql new file mode 100644 index 0000000000000..0f6f2fe7adca5 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-07-02.sql @@ -0,0 +1,2 @@ +ALTER TABLE `#__associations` ADD COLUMN `master_id` int(11) NOT NULL DEFAULT -1 COMMENT 'The master item of an association.'; +ALTER TABLE `#__associations` ADD COLUMN `master_date` datetime COMMENT 'The save or modified date of the master item.'; diff --git a/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-07-02.sql b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-07-02.sql new file mode 100644 index 0000000000000..1e0dd5bcc4b5c --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-07-02.sql @@ -0,0 +1,4 @@ +ALTER TABLE "#__associations" ADD COLUMN "master_id" integer DEFAULT -1 NOT NULL; +ALTER TABLE "#__associations" ADD COLUMN "master_date" timestamp without time zone; +COMMENT ON COLUMN "#__associations"."master_id" IS 'The master item of an association.'; +COMMENT ON COLUMN "#__associations"."master_date" IS 'The save or modified date of the master item.'; From de8a1b1ac5643e139a161eb0b308442499a13141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 8 Jul 2019 13:32:26 +0200 Subject: [PATCH 77/98] remove disabled for filters As filters are usually not disabled, these attributes are now removed. --- .../Field/ContentmasterlanguageField.php | 2 +- .../com_associations/forms/filter_associations.xml | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/administrator/components/com_associations/Field/ContentmasterlanguageField.php b/administrator/components/com_associations/Field/ContentmasterlanguageField.php index 1f907a9c2b21d..93112879b7a5c 100644 --- a/administrator/components/com_associations/Field/ContentmasterlanguageField.php +++ b/administrator/components/com_associations/Field/ContentmasterlanguageField.php @@ -49,7 +49,7 @@ public function getOptions() $contentLanguages = LanguageHelper::getContentLanguages(array(0, 1)); $options = array(); - $options[] = HTMLHelper::_('select.option', '', Text::_('JOPTION_SELECT_LANGUAGE'), array('disable'=>'true')); + $options[] = HTMLHelper::_('select.option', '', Text::_('JOPTION_SELECT_LANGUAGE')); foreach ($contentLanguages as $langCode) { diff --git a/administrator/components/com_associations/forms/filter_associations.xml b/administrator/components/com_associations/forms/filter_associations.xml index fdd625bd40f7b..00c8210378085 100644 --- a/administrator/components/com_associations/forms/filter_associations.xml +++ b/administrator/components/com_associations/forms/filter_associations.xml @@ -5,9 +5,9 @@ type="itemtype" label="COM_ASSOCIATIONS_FILTER_SELECT_ITEM_TYPE" filtermode="selector" - onchange="this.form.submit()" + onchange="this.form.submit();" > - + + > + + - - + From 04ee4a7533a0c94b6c555d2cc01e261c20d6492e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 8 Jul 2019 13:35:52 +0200 Subject: [PATCH 78/98] rename outdated into out of date --- .../com_associations/Helper/AssociationsHelper.php | 8 ++++---- .../com_associations/Helper/MasterAssociationsHelper.php | 4 ++-- .../com_associations/Model/AssociationsModel.php | 4 ++-- administrator/language/en-GB/en-GB.com_associations.ini | 2 +- administrator/language/en-GB/en-GB.ini | 4 ++-- .../language/en-GB/en-GB.plg_system_languagefilter.ini | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 0e727bf449d89..14c3deac1fc08 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -367,7 +367,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId if ($associatedModifiedMaster < $lastModifiedMaster) { // Don't display not corresponding item - if ($assocState !== 'all' && $assocState !== 'outdated') + if ($assocState !== 'all' && $assocState !== 'out_of_date') { unset($items[$langCode]); continue; @@ -381,11 +381,11 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId /* When versions are disabled then the modified date is used for the master item. That means that when no changes were made and the master item has been saved the modified date has been changed. - So the outdated state means in that case there might have been made changes and it is necessary to check manually and update the target. + So the out of date state means in that case there might have been made changes and it is necessary to check manually and update the target. */ $masterInfo = $saveHistory - ? $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') - : $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); + ? $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUT_OF_DATE_DESC') + : $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUT_OF_DATE_DESC'); } else { diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 305f734669731..977861cc3532b 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -240,8 +240,8 @@ public static function setMasterAndChildInfos($itemId, $items, $key, $item, $glo $update = true; $addClass = 'badge-warning'; $masterInfo = $saveHistory - ? '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC') - : '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC'); + ? '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUT_OF_DATE_DESC') + : '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUT_OF_DATE_DESC'); } else { diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 35169e397b83e..5156f5835eea6 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -475,8 +475,8 @@ protected function getListQuery() . ')'); } - // Outdated - if ($assocStateField === 'outdated') + // Out of date + if ($assocStateField === 'out_of_date') { // If we are on the masterlanguage and we check the state of the children $query->where('((' . $db->quoteName('asso2.master_id') . ' = ' . $db->quoteName('asso.id') diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index d708b259ef743..6ac1701e7cb44 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -46,7 +46,7 @@ COM_ASSOCIATIONS_SELECT_MENU="- Select Menu -" COM_ASSOCIATIONS_SELECT_TARGET="Select Target" COM_ASSOCIATIONS_SELECT_TARGET_LANGUAGE="- Select Target Language -" COM_ASSOCIATIONS_STATE_NOT_ASSOCIATED="Not Associated" -COM_ASSOCIATIONS_STATE_OUTDATED="Outdated" +COM_ASSOCIATIONS_STATE_OUT_OF_DATE="Out of date" COM_ASSOCIATIONS_STATE_UP_TO_DATE="Up-to-date" COM_ASSOCIATIONS_TABLE_CAPTION="Table of Associations" COM_ASSOCIATIONS_TITLE="Associations" diff --git a/administrator/language/en-GB/en-GB.ini b/administrator/language/en-GB/en-GB.ini index 8a7a3bdb3c1f7..3b618eb721812 100644 --- a/administrator/language/en-GB/en-GB.ini +++ b/administrator/language/en-GB/en-GB.ini @@ -289,9 +289,9 @@ JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE="No associations exist to propagate. JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME="Associations have been set for: %s" JGLOBAL_ASSOCIATIONS_PROPAGATE_TIP="Propagates this item's existing associations." JGLOBAL_ASSOCIATIONS_RESET_WARNING="The language has been changed. If you save this item again it will reset the available associations. If this was not intended, close the item." -JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUTDATED_DESC="This item might be out of date with the master article." +JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUT_OF_DATE_DESC="This item might be out of date with the master article." JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC="There is no association for the master language." -JGLOBAL_ASSOCIATIONS_STATE_OUTDATED_DESC="This item is out of date with the master item." +JGLOBAL_ASSOCIATIONS_STATE_OUT_OF_DATE_DESC="This item is out of date with the master item." JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC="This item is up-to-date with the master item." JGLOBAL_AUTH_ACCESS_DENIED="Access Denied" JGLOBAL_AUTH_ACCESS_GRANTED="Access Granted" diff --git a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini index 6f2e6bee7aae0..3360e265dcb6c 100644 --- a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini +++ b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini @@ -13,7 +13,7 @@ PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_LABEL="Global Master Lang PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_DESC="Note that changing this value will overwrite all existing Master Child relationships with their association states." PLG_SYSTEM_LANGUAGEFILTER_FIELD_ITEM_ASSOCIATIONS_LABEL="Item Associations" PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_LABEL="Set a Master Language?" -PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_DESC="When enabled, a master-child relationship is added between the languages. This adds an additional 'outdated' association state to a child item depending on its master. Enable versions to get a comparison view for outdated items. If this field is disabled, functions dependent on this data are not available." +PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_DESC="When enabled, a master-child relationship is added between the languages. This adds an additional 'out of date' association state to a child item depending on its master. Enable versions to get a comparison view for out of date items. If this field is disabled, functions dependent on this data are not available." PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LABEL="Add x-default Meta Tag" PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LANGUAGE_LABEL="x-default Language" PLG_SYSTEM_LANGUAGEFILTER_OPTION_DEFAULT_LANGUAGE="Default frontend language" From fcb4f223d207797b3841285deab894d522aa96b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 8 Jul 2019 14:05:38 +0200 Subject: [PATCH 79/98] move Route::_call() to the layout --- .../com_associations/Helper/MasterAssociationsHelper.php | 4 ++-- .../com_categories/Service/HTML/AdministratorService.php | 4 ++-- .../com_contact/Service/HTML/AdministratorService.php | 4 ++-- .../com_content/Service/HTML/AdministratorService.php | 4 ++-- administrator/components/com_menus/Service/HTML/Menus.php | 2 +- .../com_newsfeeds/Service/HTML/AdministratorService.php | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php index 977861cc3532b..b5330e462ae7e 100644 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php @@ -49,7 +49,7 @@ public static function addNotAssociatedMasterLink($globalMasterLang, $itemId, $i $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); $text = $globalMasterLangInfos['sef'] ? strtoupper($globalMasterLangInfos['sef']) : 'XX'; $title = Text::_('JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC'); - $url = self::getAssociationUrl($itemId, $globalMasterLang, $itemType); + $url = Route::_(self::getAssociationUrl($itemId, $globalMasterLang, $itemType)); $tooltip = '' . htmlspecialchars($globalMasterLangInfos['title'], ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . $masterInfo; @@ -291,7 +291,7 @@ public static function getAssociationUrl($itemId, $globalMasterLang, $itemType, 'target' => $target, ); - $url = Route::_('index.php?' . http_build_query($options)); + $url = 'index.php?' . http_build_query($options); return $url; } diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index 59450a5bb5ec5..2edd44b585e69 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -121,9 +121,9 @@ public function association($catid, $extension = 'com_content') $items = $classMasterInfoItems[2]; $needsUpdate = $classMasterInfoItems[3]; - $url = MasterAssociationsHelper::getAssociationUrl( + $url = Route::_(MasterAssociationsHelper::getAssociationUrl( $item->id, $globalMasterLang, $extension . '.category', $item->lang_code, $key, $masterId, $needsUpdate - ); + )); } $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index a8104077c5e4f..570b89be367a2 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -124,9 +124,9 @@ public function association($contactid) $items = $classMasterInfoItems[2]; $needsUpdate = $classMasterInfoItems[3]; - $url = MasterAssociationsHelper::getAssociationUrl( + $url = Route::_(MasterAssociationsHelper::getAssociationUrl( $item->id, $globalMasterLang, 'com_contact.contact', $item->lang_code, $key, $masterId, $needsUpdate - ); + )); } $text = strtoupper($item->lang_sef); diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index 733ed408eb07f..13e4e43eabf72 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -127,9 +127,9 @@ public function association($articleid) $items = $classMasterInfoItems[2]; $needsUpdate = $classMasterInfoItems[3]; - $url = MasterAssociationsHelper::getAssociationUrl( + $url = Route::_(MasterAssociationsHelper::getAssociationUrl( $item->id, $globalMasterLang, 'com_content.article', $item->lang_code, $key, $masterId, $needsUpdate - ); + )); } $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; diff --git a/administrator/components/com_menus/Service/HTML/Menus.php b/administrator/components/com_menus/Service/HTML/Menus.php index 17d065e41b039..a00b3508df350 100644 --- a/administrator/components/com_menus/Service/HTML/Menus.php +++ b/administrator/components/com_menus/Service/HTML/Menus.php @@ -121,7 +121,7 @@ public function association($itemid) $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); } - $url = MasterAssociationsHelper::getAssociationUrl($item->id, $globalMasterLang, 'com_menus.item', $item->lang_code, $key, $masterId); + $url = Route::_(MasterAssociationsHelper::getAssociationUrl($item->id, $globalMasterLang, 'com_menus.item', $item->lang_code, $key, $masterId)); } $text = strtoupper($item->lang_sef); diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index ee2ea53b9cec6..4c2e4566dc827 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -122,9 +122,9 @@ public function association($newsfeedid) $items = $classMasterInfoItems[2]; $needsUpdate = $classMasterInfoItems[3]; - $url = MasterAssociationsHelper::getAssociationUrl( + $url = Route::_(MasterAssociationsHelper::getAssociationUrl( $item->id, $globalMasterLang, 'com_newsfeeds.newsfeed', $item->lang_code, $key, $masterId, $needsUpdate - ); + )); } $text = strtoupper($item->lang_sef); From 059ad3254ad5fa0bec428929dff24d0d618274ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 8 Jul 2019 14:43:30 +0200 Subject: [PATCH 80/98] fix phpcs --- .../com_categories/Service/HTML/AdministratorService.php | 8 +++++--- .../com_contact/Service/HTML/AdministratorService.php | 8 +++++--- .../com_content/Service/HTML/AdministratorService.php | 8 +++++--- .../com_newsfeeds/Service/HTML/AdministratorService.php | 8 +++++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index 2edd44b585e69..afbbd031567e2 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -121,9 +121,11 @@ public function association($catid, $extension = 'com_content') $items = $classMasterInfoItems[2]; $needsUpdate = $classMasterInfoItems[3]; - $url = Route::_(MasterAssociationsHelper::getAssociationUrl( - $item->id, $globalMasterLang, $extension . '.category', $item->lang_code, $key, $masterId, $needsUpdate - )); + $url = Route::_( + MasterAssociationsHelper::getAssociationUrl( + $item->id, $globalMasterLang, $extension . '.category', $item->lang_code, $key, $masterId, $needsUpdate + ) + ); } $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index 570b89be367a2..f7ffc74f97a1f 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -124,9 +124,11 @@ public function association($contactid) $items = $classMasterInfoItems[2]; $needsUpdate = $classMasterInfoItems[3]; - $url = Route::_(MasterAssociationsHelper::getAssociationUrl( - $item->id, $globalMasterLang, 'com_contact.contact', $item->lang_code, $key, $masterId, $needsUpdate - )); + $url = Route::_( + MasterAssociationsHelper::getAssociationUrl( + $item->id, $globalMasterLang, 'com_contact.contact', $item->lang_code, $key, $masterId, $needsUpdate + ) + ); } $text = strtoupper($item->lang_sef); diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index 13e4e43eabf72..5de6252c6e04f 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -127,9 +127,11 @@ public function association($articleid) $items = $classMasterInfoItems[2]; $needsUpdate = $classMasterInfoItems[3]; - $url = Route::_(MasterAssociationsHelper::getAssociationUrl( - $item->id, $globalMasterLang, 'com_content.article', $item->lang_code, $key, $masterId, $needsUpdate - )); + $url = Route::_( + MasterAssociationsHelper::getAssociationUrl( + $item->id, $globalMasterLang, 'com_content.article', $item->lang_code, $key, $masterId, $needsUpdate + ) + ); } $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index 4c2e4566dc827..402929f24eba6 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -122,9 +122,11 @@ public function association($newsfeedid) $items = $classMasterInfoItems[2]; $needsUpdate = $classMasterInfoItems[3]; - $url = Route::_(MasterAssociationsHelper::getAssociationUrl( - $item->id, $globalMasterLang, 'com_newsfeeds.newsfeed', $item->lang_code, $key, $masterId, $needsUpdate - )); + $url = Route::_( + MasterAssociationsHelper::getAssociationUrl( + $item->id, $globalMasterLang, 'com_newsfeeds.newsfeed', $item->lang_code, $key, $masterId, $needsUpdate + ) + ); } $text = strtoupper($item->lang_sef); From 8f65a6c2b22c27eb00326f8196c19be896740074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Mon, 22 Jul 2019 13:25:28 +0200 Subject: [PATCH 81/98] fix phpcs --- .../com_associations/Helper/AssociationsHelper.php | 3 ++- .../com_associations/Model/AssociationMasterModel.php | 2 +- .../com_associations/Model/AssociationsModel.php | 11 +++++++---- .../com_associations/View/Association/HtmlView.php | 2 ++ .../com_content/Service/HTML/AdministratorService.php | 1 - libraries/src/Language/Associations.php | 1 - plugins/system/languagefilter/languagefilter.php | 3 ++- 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 6efde91d64383..6b62c630f64de 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -218,7 +218,8 @@ private static function getExtensionRealName($extensionName) * @since 3.7.0 */ public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, - $addLink = true, $assocLanguages = true, $assocState = 'all') + $addLink = true, $assocLanguages = true, $assocState = 'all' + ) { // Get the associations list for this item. $items = self::getAssociationList($extensionName, $typeName, $itemId); diff --git a/administrator/components/com_associations/Model/AssociationMasterModel.php b/administrator/components/com_associations/Model/AssociationMasterModel.php index 425cdb9cbada3..6b910636db97f 100644 --- a/administrator/components/com_associations/Model/AssociationMasterModel.php +++ b/administrator/components/com_associations/Model/AssociationMasterModel.php @@ -37,7 +37,7 @@ public function update($childId, $masterId, $itemtype) { list($extensionName, $typeName) = explode('.', $itemtype, 2); - $context = ($typeName ==='category') + $context = ($typeName === 'category') ? 'com_categories.item' : $extensionName . '.item'; $db = Factory::getDbo(); diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 5156f5835eea6..9d48d034d1628 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -177,7 +177,7 @@ protected function getListQuery() $extension = AssociationsHelper::getSupportedExtension($extensionName); $types = $extension->get('types'); - $assocContextName = ($typeName ==='category') ? 'com_categories.item' : $extensionName . '.item'; + $assocContextName = ($typeName === 'category') ? 'com_categories.item' : $extensionName . '.item'; if (array_key_exists($typeName, $types)) { @@ -472,7 +472,8 @@ protected function getListQuery() // Or a child of the master does not exist. . ' OR ( ' . $db->quoteName('asso.key') . ' IN (' . $assocQuery . ') AND ' . $db->quoteName('asso.master_id') . ' = ' . $db->quote('0') . ')' - . ')'); + . ')' + ); } // Out of date @@ -483,7 +484,8 @@ protected function getListQuery() . ' AND ' . $db->quoteName('asso2.master_date') . ' < ' . $db->quoteName('asso.master_date') . ')' // Or we are on the child language and we check its state comparing to its master. . ' OR (' . $db->quoteName('asso.master_date') . ' < ' . $db->quoteName('asso2.master_date') - . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.master_id') . '))'); + . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.master_id') . '))' + ); } // Up-to-date @@ -494,7 +496,8 @@ protected function getListQuery() . ' AND ' . $db->quoteName('asso2.master_date') . ' = ' . $db->quoteName('asso.master_date') . ')' // Or we are on the child language and we check its state comparing to its master. . ' OR (' . $db->quoteName('asso.master_date') . ' = ' . $db->quoteName('asso2.master_date') - . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.master_id') . '))'); + . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.master_id') . '))' + ); } } diff --git a/administrator/components/com_associations/View/Association/HtmlView.php b/administrator/components/com_associations/View/Association/HtmlView.php index b0cf9c4d98643..7ae9676eed2b6 100644 --- a/administrator/components/com_associations/View/Association/HtmlView.php +++ b/administrator/components/com_associations/View/Association/HtmlView.php @@ -183,6 +183,7 @@ public function display($tpl = null) $model = $this->getModel(); $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); $masterVersionIds = $model->getMasterCompareValues($referenceId, $this->targetId, $extensionName, $typeName, $typeId); + if ($masterVersionIds[0] !== null && $masterVersionIds[1] !== null) { $this->referenceVersionIdNew = $masterVersionIds[0]; @@ -190,6 +191,7 @@ public function display($tpl = null) } } } + /* * Let's put the target src into a variable to use in the javascript code * to avoid race conditions when the reference iframe loads. diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index 5b519cfc97002..b62d240110aa2 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -112,7 +112,6 @@ public function association($articleid) if ($globalMasterLang) { - // Don't continue for master, because it has been set here before if ($key === 'master') { diff --git a/libraries/src/Language/Associations.php b/libraries/src/Language/Associations.php index 70e54f0b3db97..c4914fe017fc3 100644 --- a/libraries/src/Language/Associations.php +++ b/libraries/src/Language/Associations.php @@ -126,7 +126,6 @@ public static function getAssociations($extension, $tablename, $context, $id, $p if ($items) { - foreach ($items as $tag => $item) { if ($globalMasterLang) diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index 58f737f067577..4db1a643c969a 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -1066,7 +1066,7 @@ private function _setMasterItem($language) { $resetQuery = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('master_id') . ' = ' . -1) + ->set($db->quoteName('master_id') . ' = -1') ->set($db->quoteName('master_date') . ' = NULL'); $db->setQuery($resetQuery); @@ -1212,6 +1212,7 @@ private function _setMasterItem($language) } } } + return true; } } From 197d0ce4f6111bf806b183b99eed0c5f888b4c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Wed, 7 Aug 2019 15:34:29 +0200 Subject: [PATCH 82/98] avoid using the term master All function names, variable names, comments, language constants etc have been renamed to avoid the term master. The main change of name is: - renaming master to parent - renaming global master language to default association language --- .../sql/updates/mysql/4.0.0-2019-07-02.sql | 4 +- .../updates/postgresql/4.0.0-2019-07-02.sql | 8 +- ...ler.php => DefaultAssocLangController.php} | 8 +- ...d.php => ContentdefaultassoclangField.php} | 17 +- .../Field/ItemlanguageField.php | 16 +- .../Helper/AssociationsHelper.php | 98 +++--- .../Helper/DefaultAssocLangHelper.php | 299 ++++++++++++++++++ .../Helper/MasterAssociationsHelper.php | 298 ----------------- .../Model/AssociationModel.php | 30 +- .../Model/AssociationsModel.php | 42 +-- ...terModel.php => DefaultAssocLangModel.php} | 20 +- .../View/Association/HtmlView.php | 24 +- .../View/Associations/HtmlView.php | 6 +- .../forms/filter_associations.xml | 2 +- .../layouts/joomla/searchtools/default.php | 9 +- .../tmpl/association/update.php | 2 +- .../tmpl/associations/default.php | 6 +- .../com_categories/Model/CategoryModel.php | 22 +- .../Service/HTML/AdministratorService.php | 68 ++-- .../tmpl/categories/default.php | 4 +- .../Service/HTML/AdministratorService.php | 68 ++-- .../Service/HTML/AdministratorService.php | 68 ++-- ...mparemaster.php => compareassocparent.php} | 2 +- .../components/com_menus/Model/ItemModel.php | 14 +- .../com_menus/Service/HTML/Menus.php | 56 ++-- .../Service/HTML/AdministratorService.php | 64 ++-- .../language/en-GB/en-GB.com_associations.ini | 2 +- administrator/language/en-GB/en-GB.ini | 12 +- .../en-GB/en-GB.plg_system_languagefilter.ini | 8 +- .../templates/atum/scss/template.scss | 4 +- ...6.js => admin-compare-assoc-parent.es6.js} | 0 .../js/sidebysideupdate.es6.js | 2 +- installation/sql/mysql/joomla.sql | 4 +- installation/sql/postgresql/joomla.sql | 8 +- installation/src/Model/LanguagesModel.php | 18 +- layouts/joomla/content/associations.php | 8 +- libraries/src/Language/Associations.php | 18 +- libraries/src/MVC/Model/AdminModel.php | 36 +-- plugins/sampledata/multilang/multilang.php | 4 +- .../system/languagefilter/languagefilter.php | 104 +++--- .../system/languagefilter/languagefilter.xml | 14 +- 41 files changed, 748 insertions(+), 749 deletions(-) rename administrator/components/com_associations/Controller/{AssociationMasterController.php => DefaultAssocLangController.php} (73%) rename administrator/components/com_associations/Field/{ContentmasterlanguageField.php => ContentdefaultassoclangField.php} (73%) create mode 100644 administrator/components/com_associations/Helper/DefaultAssocLangHelper.php delete mode 100644 administrator/components/com_associations/Helper/MasterAssociationsHelper.php rename administrator/components/com_associations/Model/{AssociationMasterModel.php => DefaultAssocLangModel.php} (68%) rename administrator/components/com_contenthistory/tmpl/compare/{comparemaster.php => compareassocparent.php} (96%) rename build/media_source/com_associations/js/{admin-compare-master.es6.js => admin-compare-assoc-parent.es6.js} (100%) diff --git a/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-07-02.sql b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-07-02.sql index 0f6f2fe7adca5..41ab9cb4807aa 100644 --- a/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-07-02.sql +++ b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-07-02.sql @@ -1,2 +1,2 @@ -ALTER TABLE `#__associations` ADD COLUMN `master_id` int(11) NOT NULL DEFAULT -1 COMMENT 'The master item of an association.'; -ALTER TABLE `#__associations` ADD COLUMN `master_date` datetime COMMENT 'The save or modified date of the master item.'; +ALTER TABLE `#__associations` ADD COLUMN `parent_id` int(11) NOT NULL DEFAULT -1 COMMENT 'The parent of an association.'; +ALTER TABLE `#__associations` ADD COLUMN `parent_date` datetime COMMENT 'The save or modified date of the parent.'; diff --git a/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-07-02.sql b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-07-02.sql index 1e0dd5bcc4b5c..25fc0fd66f80a 100644 --- a/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-07-02.sql +++ b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-07-02.sql @@ -1,4 +1,4 @@ -ALTER TABLE "#__associations" ADD COLUMN "master_id" integer DEFAULT -1 NOT NULL; -ALTER TABLE "#__associations" ADD COLUMN "master_date" timestamp without time zone; -COMMENT ON COLUMN "#__associations"."master_id" IS 'The master item of an association.'; -COMMENT ON COLUMN "#__associations"."master_date" IS 'The save or modified date of the master item.'; +ALTER TABLE "#__associations" ADD COLUMN "parent_id" integer DEFAULT -1 NOT NULL; +ALTER TABLE "#__associations" ADD COLUMN "parent_date" timestamp without time zone; +COMMENT ON COLUMN "#__associations"."parent_id" IS 'The parent of an association.'; +COMMENT ON COLUMN "#__associations"."parent_date" IS 'The save or modified date of the parent.'; diff --git a/administrator/components/com_associations/Controller/AssociationMasterController.php b/administrator/components/com_associations/Controller/DefaultAssocLangController.php similarity index 73% rename from administrator/components/com_associations/Controller/AssociationMasterController.php rename to administrator/components/com_associations/Controller/DefaultAssocLangController.php index a4566309071c9..361ceac1f9e8f 100644 --- a/administrator/components/com_associations/Controller/AssociationMasterController.php +++ b/administrator/components/com_associations/Controller/DefaultAssocLangController.php @@ -19,10 +19,10 @@ * * @since 4.0 */ -class AssociationMasterController extends BaseController +class DefaultAssocLangController extends BaseController { /** - * Method to update the childs modified date of the master item in the associations table. + * Method to update the childs modified date of the parent in the associations table. * * @return void * @@ -31,10 +31,10 @@ class AssociationMasterController extends BaseController public function update() { $targetId = $this->input->get('targetId', '', 'int'); - $masterId = $this->input->get('id', '', 'int'); + $parentId = $this->input->get('id', '', 'int'); $itemtype = $this->input->get('itemtype', '', 'string'); - $this->getModel('associationmaster')->update($targetId, $masterId, $itemtype); + $this->getModel('defaultassoclang')->update($targetId, $parentId, $itemtype); $this->setRedirect(Route::_('index.php?option=com_associations&view=associations', false)); } diff --git a/administrator/components/com_associations/Field/ContentmasterlanguageField.php b/administrator/components/com_associations/Field/ContentdefaultassoclangField.php similarity index 73% rename from administrator/components/com_associations/Field/ContentmasterlanguageField.php rename to administrator/components/com_associations/Field/ContentdefaultassoclangField.php index 93112879b7a5c..ebd884b414126 100644 --- a/administrator/components/com_associations/Field/ContentmasterlanguageField.php +++ b/administrator/components/com_associations/Field/ContentdefaultassoclangField.php @@ -20,11 +20,11 @@ /** - * Content Master Languages Field class. + * Content Association Languages Field class. * * @since 4.0 */ -class ContentmasterlanguageField extends ContentlanguageField +class ContentdefaultassoclangField extends ContentlanguageField { /** * The list field type. @@ -33,7 +33,7 @@ class ContentmasterlanguageField extends ContentlanguageField * * @since 4.0 */ - public $type = 'contentmasterlanguage'; + public $type = 'contentdefaultassoclang'; /** * Method to get the field options. @@ -44,19 +44,18 @@ class ContentmasterlanguageField extends ContentlanguageField */ public function getOptions() { - $globalMasterLang = Associations::getGlobalMasterLanguage(); - + $defaultAssocLang = Associations::getDefaultAssocLang(); $contentLanguages = LanguageHelper::getContentLanguages(array(0, 1)); - $options = array(); + $options = array(); $options[] = HTMLHelper::_('select.option', '', Text::_('JOPTION_SELECT_LANGUAGE')); foreach ($contentLanguages as $langCode) { - // Add information to the language if it is the global master language - if ($langCode->lang_code == $globalMasterLang) + // Add information to the language if it is the default association language. + if ($langCode->lang_code == $defaultAssocLang) { - $options[] = HTMLHelper::_('select.option', $langCode->lang_code, $langCode->title . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE')); + $options[] = HTMLHelper::_('select.option', $langCode->lang_code, $langCode->title . ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_DEFAULT_ASSOC_LANG')); } else { diff --git a/administrator/components/com_associations/Field/ItemlanguageField.php b/administrator/components/com_associations/Field/ItemlanguageField.php index de884af2bde7f..903e2fc6f6c06 100644 --- a/administrator/components/com_associations/Field/ItemlanguageField.php +++ b/administrator/components/com_associations/Field/ItemlanguageField.php @@ -64,9 +64,9 @@ protected function getOptions() // Gets existing languages. $existingLanguages = LanguageHelper::getContentLanguages(array(0, 1)); - // Get global master language and check if reference is a master item. - $globalMasterLang = Associations::getGlobalMasterLanguage(); - $refIsMaster = $referenceLang === $globalMasterLang; + // Get default association language and check if reference is a parent. + $defaultAssocLang = Associations::getDefaultAssocLang(); + $refIsParent = $referenceLang === $defaultAssocLang; $options = array(); @@ -79,10 +79,10 @@ protected function getOptions() continue; } - if ($globalMasterLang && !$refIsMaster) + if ($defaultAssocLang && !$refIsParent) { - // If reference is a child then display just the master language - if ($language->lang_code !== $globalMasterLang) + // If reference is a child then display just the default association language + if ($language->lang_code !== $defaultAssocLang) { continue; } @@ -91,9 +91,9 @@ protected function getOptions() $options[$langCode] = new \stdClass; $options[$langCode]->text = $language->title; - if ($globalMasterLang && ($language->lang_code === $globalMasterLang)) + if ($defaultAssocLang && ($language->lang_code === $defaultAssocLang)) { - $options[$langCode]->text .= ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE'); + $options[$langCode]->text .= ' - ' . Text::_('JGLOBAL_ASSOCIATIONS_DEFAULT_ASSOC_LANG'); } // If association exists in this language. diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 6b62c630f64de..70ec6be46d60e 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -211,7 +211,7 @@ private static function getExtensionRealName($extensionName) * @param string $itemLanguage Item language code. * @param boolean $addLink True for adding edit links. False for just text. * @param boolean $assocLanguages True for showing non associated content languages. False only languages with associations. - * @param string $assocState The filter association state, enabled when a global master language is used. + * @param string $assocState The filter association state, enabled when a default association language is used. * * @return string The language HTML * @@ -232,8 +232,8 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $canEditReference = self::allowEdit($extensionName, $typeName, $itemId); $canCreate = self::allowAdd($extensionName, $typeName); - // Get the global master language, empty if not used - $globalMasterLang = Associations::getGlobalMasterLanguage(); + // Get the default association language, empty if not used + $defaultAssocLang = Associations::getDefaultAssocLang(); // Check if versions are enabled $saveHistory = ComponentHelper::getParams($extensionName)->get('save_history', 0); @@ -241,9 +241,9 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId if ($items) { - // Get master dates of each item of an association and the master id. - $assocMasterDates = MasterAssociationsHelper::getMasterDates($items, $context); - $masterId = $items[$globalMasterLang]['id'] ?? null; + // Get parent dates of each item of an association and the parent id. + $assocParentDates = DefaultAssocLangHelper::getParentDates($items, $context); + $parentId = $items[$defaultAssocLang]['id'] ?? null; } // Create associated items list. @@ -251,9 +251,9 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId { // Defaults $update = false; - $masterInfo = ''; + $parentChildInfo = ''; - if (!$globalMasterLang) + if (!$defaultAssocLang) { // Don't do for the reference language. if ($langCode == $itemLanguage) @@ -278,10 +278,10 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId // Get html parameters for associated items. if (isset($items[$langCode])) { - if ($globalMasterLang) + if ($defaultAssocLang) { // Don't display any other children to the child item. - if (($itemLanguage !== $globalMasterLang) && ($langCode !== $globalMasterLang) && ($langCode !== $itemLanguage)) + if (($itemLanguage !== $defaultAssocLang) && ($langCode !== $defaultAssocLang) && ($langCode !== $itemLanguage)) { unset($items[$langCode]); continue; @@ -328,18 +328,18 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId && self::allowEdit($extensionName, $typeName, $items[$langCode]['id']) && self::canCheckinItem($extensionName, $typeName, $items[$langCode]['id']); - $masterInfoSpace = $additional && !$addLink ? '
      ' : '

      '; + $parentChildInfoSpace = $additional && !$addLink ? '
      ' : '

      '; - if ($globalMasterLang) + if ($defaultAssocLang) { - // Settings for the master language - if ($globalMasterLang === $langCode) + // Settings for the default association language. + if ($defaultAssocLang === $langCode) { - $labelClass .= ' master-item'; + $labelClass .= ' parent-item'; $additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : ''; - $masterInfo = $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); + $parentChildInfo = $parentChildInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_DEFAULT_ASSOC_LANG_ITEM'); - if ($globalMasterLang === $itemLanguage) + if ($defaultAssocLang === $itemLanguage) { // Do not define any child target as there can be more than one $target = ''; @@ -352,18 +352,18 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId // Setting for children else { - // When there is no associated master item, set it to target - if (!$masterId) + // When there is no associated parent, set it to target + if (!$parentId) { - $target = $globalMasterLang . ':0:add'; + $target = $defaultAssocLang . ':0:add'; } - if (array_key_exists($items[$langCode]['id'], $assocMasterDates) && array_key_exists($masterId, $assocMasterDates)) + if (array_key_exists($items[$langCode]['id'], $assocParentDates) && array_key_exists($parentId, $assocParentDates)) { - $associatedModifiedMaster = $assocMasterDates[$items[$langCode]['id']]; - $lastModifiedMaster = $assocMasterDates[$masterId]; + $associatedModifiedParent = $assocParentDates[$items[$langCode]['id']]; + $lastModifiedParent = $assocParentDates[$parentId]; - if ($associatedModifiedMaster < $lastModifiedMaster) + if ($associatedModifiedParent < $lastModifiedParent) { // Don't display not corresponding item if ($assocState !== 'all' && $assocState !== 'out_of_date') @@ -378,13 +378,13 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $update = true; /* - When versions are disabled then the modified date is used for the master item. - That means that when no changes were made and the master item has been saved the modified date has been changed. - So the out of date state means in that case there might have been made changes and it is necessary to check manually and update the target. + When versions are disabled then the modified date is used for the parent. + That means that when no changes were made and the parent has been saved the modified date has been changed. + So the out-of-date state means in that case there might have been made changes and it is necessary to check manually and update the target. */ - $masterInfo = $saveHistory - ? $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUT_OF_DATE_DESC') - : $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUT_OF_DATE_DESC'); + $parentChildInfo = $saveHistory + ? $parentChildInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUT_OF_DATE_DESC') + : $parentChildInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUT_OF_DATE_DESC'); } else { @@ -396,12 +396,12 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId } $additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : ''; - $masterInfo = $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); + $parentChildInfo = $parentChildInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); // For item types that do not use modified date or versions like menu items - if (!$associatedModifiedMaster) + if (!$associatedModifiedParent) { - $masterInfo = ''; + $parentChildInfo = ''; } } } @@ -416,9 +416,9 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId else { // Don't display any other children to the child item - if ($globalMasterLang && ($itemLanguage != $globalMasterLang) + if ($defaultAssocLang && ($itemLanguage != $defaultAssocLang) && ($langCode != $itemLanguage) - && ($langCode != $globalMasterLang)) + && ($langCode != $defaultAssocLang)) { continue; } @@ -431,14 +431,14 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $target = $langCode . ':0:add'; $allow = $canCreate; - if ($globalMasterLang) + if ($defaultAssocLang) { - if ($globalMasterLang === $langCode) + if ($defaultAssocLang === $langCode) { - $labelClass .= ' master-item'; - $masterInfoSpace = $addLink ? '

      ' : ''; - $masterInfo = $masterInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); - $target = ''; + $labelClass .= ' parent-item'; + $parentChildInfoSpace = $addLink ? '

      ' : ''; + $parentChildInfo = $parentChildInfoSpace . Text::_('JGLOBAL_ASSOCIATIONS_DEFAULT_ASSOC_LANG_ITEM'); + $target = ''; } else { @@ -450,10 +450,10 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId } } - // Change target, when there is no association with the global master language for the child item - if ($globalMasterLang !== $itemLanguage) + // Change target, when there is no association with the default association language for the child item + if ($defaultAssocLang !== $itemLanguage) { - $target = $globalMasterLang . ':0:add'; + $target = $defaultAssocLang . ':0:add'; } } } @@ -465,7 +465,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId 'layout' => $update ? 'update' : 'edit', 'itemtype' => $extensionName . '.' . $typeName, 'task' => 'association.edit', - 'id' => $masterId ?? $itemId, + 'id' => $parentId ?? $itemId, 'target' => $target, ); @@ -474,16 +474,16 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $text = strtoupper($language->sef); $tooltip = '' . htmlspecialchars($language->title, ENT_QUOTES, 'UTF-8') . '
      ' - . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '

      ' . $additional . $masterInfo; + . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '

      ' . $additional . $parentChildInfo; $classes = 'badge ' . $labelClass; $items[$langCode]['link'] = '' . $text . '' . '
      ' . $tooltip . '
      '; - // Reorder the array, so the master item gets to the first place - if ($langCode === $globalMasterLang) + // Reorder the array, so the parent gets to the first place + if ($langCode === $defaultAssocLang) { - $items = array('master' => $items[$langCode]) + $items; + $items = array('parent' => $items[$langCode]) + $items; unset($items[$langCode]); } } diff --git a/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php b/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php new file mode 100644 index 0000000000000..c0076c2b5fa58 --- /dev/null +++ b/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php @@ -0,0 +1,299 @@ +getQuery(true) + ->select('title, sef') + ->from('#__languages') + ->where($db->quoteName('lang_code') . ' = ' . $db->quote($defaultAssocLang)); + $db->setQuery($query); + $defaultAssocLangInfos = $db->loadAssoc(); + + $classes = 'badge badge-secondary'; + $parentChildInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_DEFAULT_ASSOC_LANG_ITEM'); + $text = $defaultAssocLangInfos['sef'] ? strtoupper($defaultAssocLangInfos['sef']) : 'XX'; + $title = Text::_('JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC'); + $url = Route::_(self::getAssociationUrl($itemId, $defaultAssocLang, $itemType)); + + $tooltip = '' . htmlspecialchars($defaultAssocLangInfos['title'], ENT_QUOTES, 'UTF-8') . '
      ' + . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . $parentChildInfo; + + $link = '' . $text . '' + . ''; + + return $link; + } + + /** + * Method to get parent dates of each item of an association + * + * @param array $associations the associations to be saved + * @param string $context the association context + * + * @return array association with parent dates + */ + public static function getParentDates($associations, $context) + { + $db = Factory::getDbo(); + + foreach ($associations as $langCode => $id) + { + if (is_array($id)) + { + $id = $id['id']; + } + + $query = $db->getQuery(true) + ->select($db->quoteName('parent_date')) + ->from($db->quoteName('#__associations')) + ->where($db->quoteName('id') . ' = ' . $db->quote($id)) + ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + $db->setQuery($query); + $parentDates[$id] = $db->loadResult(); + } + + return $parentDates; + } + + /** + * Method to get parent_id and parent_date for an association going to be saved. + * + * @param integer $id Item id + * @param integer $dataId Item id of an item that is going to be saved + * @param integer $parentId Id of the associated parent + * @param string $parentModified The latest modified date of the parent + * @param array $assocParentDates Parents modified date of an associated item + * @param string $old_key The old association key to check if it is a new association + * + * @return array parent id and parent dates for an associated item + */ + public static function getParentValues($id, $dataId, $parentId, $parentModified, $assocParentDates, $old_key) + { + if ($parentId) + { + // For the parent + if ($parentId === $id) + { + $parentIdValue = 0; + + // Set always the last modified date + $parentDateValue = $parentModified ?? 'NULL'; + } + + // For the children + else + { + $parentIdValue = $parentId; + + // If modified date isn't set to the child item, set current modified date from parent. + $parentDateValue = empty($assocParentDates[$id]) + ? $parentModified + : $assocParentDates[$id]; + + if (!$old_key && ($dataId === $id)) + { + // Add modified date from parent to new associated item + $parentDateValue = $parentModified ?? 'NULL'; + } + } + } + else + { + // Default values when there is no associated parent. + $parentIdValue = -1; + $parentDateValue = 'NULL'; + } + + return [(int) $parentIdValue, $parentDateValue]; + } + + /** + * Method to get the latest modified date of a parent + * + * @param integer $parentId Id of the associated parent + * @param string $tableName The name of the table + * @param string $typeAlias Alias for the content type + * + * @return string The modified date of the parent + */ + public static function getParentModifiedDate($parentId, $tableName, $typeAlias) + { + // Check if the content version is enabled + $aliasParts = explode('.', $typeAlias); + $saveHistory = ComponentHelper::getParams($aliasParts[0])->get('save_history', 0); + $contentTypeTable = Table::getInstance('ContentType'); + $contentTypeTblName = $contentTypeTable->getTableName(); + $typeId = $contentTypeTable->getTypeId($typeAlias); + + $db = Factory::getDbo(); + $fieldMapsQuery = $db->getQuery(true) + ->select($db->quoteName('field_mappings')) + ->from($db->quoteName($contentTypeTblName)) + ->where($db->quoteName('type_id') . ' = ' . $db->quote($typeId)); + $db->setQuery($fieldMapsQuery); + $fieldMaps = $db->loadResult(); + + $modifiedColumn = json_decode($fieldMaps)->common->core_modified_time; + + if ($parentId) + { + // If versions are enabled get the save_date of the parent from history table + if ($saveHistory) + { + $parentHistory = ContentHistoryHelper::getHistory($typeId, $parentId); + + // Latest saved date of the parent + $parentModified = $parentHistory[0]->save_date; + } + else + { + $parentDateQuery = $db->getQuery(true) + ->select($db->quoteName($modifiedColumn)) + ->from($db->quoteName($tableName)) + ->where($db->quoteName('id') . ' = ' . $db->quote($parentId)); + $db->setQuery($parentDateQuery); + $parentModified = $db->loadResult(); + } + } + + return $parentModified ?? ''; + } + + /** + * Method to set class name and information about the association state or the parent. + * + * @param integer $itemId Item id + * @param array $items The associated items for the item with the itemId + * @param integer $key The current key from $items that is currently going through the foreach loop + * @param array $item The current value from $items that is currently going through the foreach loop + * @param string $defaultAssocLang The default association language + * @param boolean $isParent If the item with $itemId is a parent + * @param integer $parentId Id of the associated parent + * @param array $assocParentDates Parent Dates of each associated item + * @param boolean $saveHistory If Versions are enabled or not + * + * @return array the className and parentInfo for the association state, the array $items back and boolean if item needs update. + */ + public static function setParentAndChildInfos($itemId, $items, $key, $item, $defaultAssocLang, $isParent, $parentId, $assocParentDates, $saveHistory) + { + + $addClass = 'badge-success'; + $parentInfo = ''; + $update = false; + + // Don't display other children if the current item is a child. + if (($key !== $itemId) && ($defaultAssocLang !== $item->lang_code) && !$isParent) + { + unset($items[$key]); + } + + if ($key === $parentId) + { + $addClass .= ' parent-item'; + $parentInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_DEFAULT_ASSOC_LANG_ITEM'); + } + else + { + // Get association state of child when a parent item exists + if ($parentId && (array_key_exists($key, $assocParentDates)) && (array_key_exists($parentId, $assocParentDates))) + { + $associatedModifiedParent = $assocParentDates[$key]; + $lastModifiedParent = $assocParentDates[$parentId]; + + if ($associatedModifiedParent < $lastModifiedParent) + { + $update = true; + $addClass = 'badge-warning'; + $parentInfo = $saveHistory + ? '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUT_OF_DATE_DESC') + : '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUT_OF_DATE_DESC'); + } + else + { + $addClass = 'badge-success'; + $parentInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); + } + } + } + + return [$addClass, $parentInfo, $items, $update]; + } + + /** + * Method to get the association url for an item + * + * @param integer $itemId The item id + * @param string $defaultAssocLang The default association language + * @param string $itemType The item type + * @param string $itemLang The current value from $items that is currently going through the foreach loop + * @param integer $key The current key from $items that is currently going through the foreach loop + * @param integer $parentId Id of the associated parent + * @param boolean $needsUpdate If the item needs an update or not + * + * @return string + */ + public static function getAssociationUrl($itemId, $defaultAssocLang, $itemType, $itemLang = '', $key = '', $parentId = '', $needsUpdate = false) + { + $target = ''; + + if (empty($parentId)) + { + $target = $defaultAssocLang . ':0:add'; + } + elseif ($key !== $parentId) + { + $target = $itemLang . ':' . $itemId . ':edit'; + } + + // Generate item Html. + $options = array( + 'option' => 'com_associations', + 'view' => 'association', + 'layout' => $needsUpdate ? 'update' : 'edit', + 'itemtype' => $itemType, + 'task' => 'association.edit', + 'id' => empty($parentId) ? $itemId : $parentId, + 'target' => $target, + ); + + $url = 'index.php?' . http_build_query($options); + + return $url; + } +} diff --git a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php b/administrator/components/com_associations/Helper/MasterAssociationsHelper.php deleted file mode 100644 index b5330e462ae7e..0000000000000 --- a/administrator/components/com_associations/Helper/MasterAssociationsHelper.php +++ /dev/null @@ -1,298 +0,0 @@ -getQuery(true) - ->select('title, sef') - ->from('#__languages') - ->where($db->quoteName('lang_code') . ' = ' . $db->quote($globalMasterLang)); - $db->setQuery($query); - $globalMasterLangInfos = $db->loadAssoc(); - - $classes = 'badge badge-secondary'; - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); - $text = $globalMasterLangInfos['sef'] ? strtoupper($globalMasterLangInfos['sef']) : 'XX'; - $title = Text::_('JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC'); - $url = Route::_(self::getAssociationUrl($itemId, $globalMasterLang, $itemType)); - - $tooltip = '' . htmlspecialchars($globalMasterLangInfos['title'], ENT_QUOTES, 'UTF-8') . '
      ' - . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . $masterInfo; - - $link = '' . $text . '' - . ''; - - return $link; - } - - /** - * Method to get master dates of each item of an association. - * - * @param array $associations the associations to be saved. - * @param string $context the association context - * - * @return array association with master dates - */ - public static function getMasterDates($associations, $context) - { - $db = Factory::getDbo(); - - foreach ($associations as $langCode => $id) - { - if (is_array($id)) - { - $id = $id['id']; - } - - $query = $db->getQuery(true) - ->select($db->quoteName('master_date')) - ->from($db->quoteName('#__associations')) - ->where($db->quoteName('id') . ' = ' . $db->quote($id)) - ->where($db->quoteName('context') . ' = ' . $db->quote($context)); - $db->setQuery($query); - $masterDates[$id] = $db->loadResult(); - } - - return $masterDates; - } - - /** - * Method to get master_id and master_date for an association going to be saved. - * - * @param integer $id Item id - * @param integer $dataId Item id of an item that is going to be saved - * @param integer $masterId Id of the associated master item - * @param string $masterModified The latest modified date of the master - * @param array $assocMasterDates Masters modified date of an associated item - * @param string $old_key The old association key to check if it is a new association - * - * @return array master id and master dates for an associated item - */ - public static function getMasterValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $old_key) - { - if ($masterId) - { - // For the master item - if ($masterId === $id) - { - $masterIdValue = 0; - - // Set always the last modified date - $masterDateValue = $masterModified ?? 'NULL'; - } - - // For the children - else - { - $masterIdValue = $masterId; - - // If modified date isn't set to the child item, set current modified date from master. - $masterDateValue = empty($assocMasterDates[$id]) - ? $masterModified - : $assocMasterDates[$id]; - - if (!$old_key && ($dataId === $id)) - { - // Add modified date from master to new associated item - $masterDateValue = $masterModified ?? 'NULL'; - } - } - } - else - { - // Default values when there is no associated master item. - $masterIdValue = -1; - $masterDateValue = 'NULL'; - } - - return [(int) $masterIdValue, $masterDateValue]; - } - - /** - * Method to get the latest modified date of a master item - * - * @param integer $masterId Id of the associated master item - * @param string $tableName The name of the table. - * @param string $typeAlias Alias for the content type - * - * @return string The modified date of the master item - */ - public static function getMasterModifiedDate($masterId, $tableName, $typeAlias) - { - // Check if the content version is enabled - $aliasParts = explode('.', $typeAlias); - $saveHistory = ComponentHelper::getParams($aliasParts[0])->get('save_history', 0); - $contentTypeTable = Table::getInstance('ContentType'); - $contentTypeTblName = $contentTypeTable->getTableName(); - $typeId = $contentTypeTable->getTypeId($typeAlias); - - $db = Factory::getDbo(); - $fieldMapsQuery = $db->getQuery(true) - ->select($db->quoteName('field_mappings')) - ->from($db->quoteName($contentTypeTblName)) - ->where($db->quoteName('type_id') . ' = ' . $db->quote($typeId)); - $db->setQuery($fieldMapsQuery); - $fieldMaps = $db->loadResult(); - - $modifiedColumn = json_decode($fieldMaps)->common->core_modified_time; - - if ($masterId) - { - // If versions are enabled get the save_date of the master item from history table - if ($saveHistory) - { - $masterHistory = ContentHistoryHelper::getHistory($typeId, $masterId); - - // Latest saved date of the master item - $masterModified = $masterHistory[0]->save_date; - } - else - { - $masterDateQuery = $db->getQuery(true) - ->select($db->quoteName($modifiedColumn)) - ->from($db->quoteName($tableName)) - ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); - $db->setQuery($masterDateQuery); - $masterModified = $db->loadResult(); - } - } - - return $masterModified ?? ''; - } - - /** - * Method to set class name and information about the association state or the master item. - * - * @param integer $itemId Item id - * @param array $items The associated items for the item with the itemId - * @param integer $key The current key from $items that is currently going through the foreach loop. - * @param array $item The current value from $items that is currently going through the foreach loop. - * @param boolean $isMaster If the item with $itemId is a master item. - * @param integer $masterId Id of the associated master item. - * @param array $assocMasterDates Master Dates of each associated item. - * @param boolean $saveHistory If Versions are enabled or not. - * - * @return array the className and masterInfo for the association state, the array $items back and boolean if item needs update. - */ - public static function setMasterAndChildInfos($itemId, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory) - { - - $addClass = 'badge-success'; - $masterInfo = ''; - $update = false; - - // Don't display other children if the current item is a child of the master language. - if (($key !== $itemId) && ($globalMasterLang !== $item->lang_code) && !$isMaster) - { - unset($items[$key]); - } - - if ($key === $masterId) - { - $addClass .= ' master-item'; - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); - } - else - { - // Get association state of child when a master exists - if ($masterId && (array_key_exists($key, $assocMasterDates)) && (array_key_exists($masterId, $assocMasterDates))) - { - $associatedModifiedMaster = $assocMasterDates[$key]; - $lastModifiedMaster = $assocMasterDates[$masterId]; - - if ($associatedModifiedMaster < $lastModifiedMaster) - { - $update = true; - $addClass = 'badge-warning'; - $masterInfo = $saveHistory - ? '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_OUT_OF_DATE_DESC') - : '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUT_OF_DATE_DESC'); - } - else - { - $addClass = 'badge-success'; - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC'); - } - } - } - - return [$addClass, $masterInfo, $items, $update]; - } - - /** - * Method to get the association url for an item - * - * @param integer $itemId The item id - * @param string $globalMasterLang The global master language - * @param string $itemType The item type - * @param string $itemLang The current value from $items that is currently going through the foreach loop. - * @param integer $key The current key from $items that is currently going through the foreach loop. - * @param integer $masterId Id of the associated master item. - * @param boolean $needsUpdate If the item needs an update or not. - * - * @return string - */ - public static function getAssociationUrl($itemId, $globalMasterLang, $itemType, $itemLang = '', $key = '', $masterId = '', $needsUpdate = false) - { - $target = ''; - - if (empty($masterId)) - { - $target = $globalMasterLang . ':0:add'; - } - elseif ($key !== $masterId) - { - $target = $itemLang . ':' . $itemId . ':edit'; - } - - // Generate item Html. - $options = array( - 'option' => 'com_associations', - 'view' => 'association', - 'layout' => $needsUpdate ? 'update' : 'edit', - 'itemtype' => $itemType, - 'task' => 'association.edit', - 'id' => empty($masterId) ? $itemId : $masterId, - 'target' => $target, - ); - - $url = 'index.php?' . http_build_query($options); - - return $url; - } -} diff --git a/administrator/components/com_associations/Model/AssociationModel.php b/administrator/components/com_associations/Model/AssociationModel.php index 455c3b2e0d2e5..bf7ddeb8dde23 100644 --- a/administrator/components/com_associations/Model/AssociationModel.php +++ b/administrator/components/com_associations/Model/AssociationModel.php @@ -40,17 +40,17 @@ public function getForm($data = array(), $loadData = true) } /** - * Method to get the history version ids of a master item. + * Method to get the history version ids of a parent. * - * @param integer $masterId Id of the master item - * @param integer $targetId Id of an child item + * @param integer $parentId Id of the parent + * @param integer $targetId Id of a child * @param string $extensionName The extension name with com_ * @param string $typeName The item type * @param integer $typeId the content type id * * @return array Array containing two version history ids */ - public function getMasterCompareValues($masterId, $targetId, $extensionName, $typeName, $typeId) + public function getParentCompareValues($parentId, $targetId, $extensionName, $typeName, $typeId) { $context = ($typeName === 'category') @@ -58,35 +58,35 @@ public function getMasterCompareValues($masterId, $targetId, $extensionName, $ty : $extensionName . '.item'; $db = Factory::getDbo(); - $masterQuery = $db->getQuery(true) - ->select($db->quoteName('master_date')) + $parentQuery = $db->getQuery(true) + ->select($db->quoteName('parent_date')) ->from($db->quoteName('#__associations')) - ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('id') . ' = ' . $db->quote($parentId)) ->where($db->quoteName('context') . ' = ' . $db->quote($context)); - $latestMasterDate = $db->setQuery($masterQuery)->loadResult(); + $latestParentDate = $db->setQuery($parentQuery)->loadResult(); $latestVersionQuery = $db->getQuery(true) ->select($db->quoteName('version_id')) ->from($db->quoteName('#__ucm_history')) - ->where($db->quoteName('ucm_item_id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('ucm_item_id') . ' = ' . $db->quote($parentId)) ->where($db->quoteName('ucm_type_id') . ' = ' . $db->quote($typeId)) - ->where($db->quoteName('save_date') . ' = ' . $db->quote($latestMasterDate)); + ->where($db->quoteName('save_date') . ' = ' . $db->quote($latestParentDate)); $latestVersionId = $db->setQuery($latestVersionQuery)->loadResult(); $childQuery = $db->getQuery(true) - ->select($db->quoteName('master_date')) + ->select($db->quoteName('parent_date')) ->from($db->quoteName('#__associations')) ->where($db->quoteName('id') . ' = ' . $db->quote($targetId)) - ->where($db->quoteName('master_id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('parent_id') . ' = ' . $db->quote($parentId)) ->where($db->quoteName('context') . ' = ' . $db->quote($context)); - $childMasterDate = $db->setQuery($childQuery)->loadResult(); + $childParentDate = $db->setQuery($childQuery)->loadResult(); $olderVersionQuery = $db->getQuery(true) ->select($db->quoteName('version_id')) ->from($db->quoteName('#__ucm_history')) - ->where($db->quoteName('ucm_item_id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('ucm_item_id') . ' = ' . $db->quote($parentId)) ->where($db->quoteName('ucm_type_id') . ' = ' . $db->quote($typeId)) - ->where($db->quoteName('save_date') . ' = ' . $db->quote($childMasterDate)); + ->where($db->quoteName('save_date') . ' = ' . $db->quote($childParentDate)); $olderVersionId = $db->setQuery($olderVersionQuery)->loadResult(); return [$latestVersionId, $olderVersionId]; diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 9d48d034d1628..b82c825980aad 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -82,11 +82,11 @@ protected function populateState($ordering = 'ordering', $direction = 'asc') $forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd'); $forcedItemType = $app->input->get('forcedItemType', '', 'string'); - // Set language select box to default site language or if set to, to the master language as default. - $globalMasterLang = Associations::getGlobalMasterLanguage(); - $langParam = ComponentHelper::getParams('com_languages'); + // Set language select box to default site language or if set to, to the default association language as default. + $defaultAssocLang = Associations::getDefaultAssocLang(); + $langParam = ComponentHelper::getParams('com_languages'); - $defaultLanguage = empty($globalMasterLang) ? $langParam->get('site') : $globalMasterLang; + $defaultLanguage = empty($defaultAssocLang) ? $langParam->get('site') : $defaultAssocLang; $defaultItemType = 'com_content.article'; // Adjust the context to support modal layouts. @@ -467,36 +467,36 @@ protected function getListQuery() // Join over associations where id does not exist $query->where('((' . $db->quoteName('asso.id') . ' IS NULL )' - // Or if we are on the child language and there is no master language - . ' OR ( ' . $db->quoteName('asso2.master_id') . ' = ' . $db->quote('-1') . ')' - // Or a child of the master does not exist. + // Or if we are on the child language and there is no parent + . ' OR ( ' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quote('-1') . ')' + // Or a child of the parent does not exist. . ' OR ( ' . $db->quoteName('asso.key') . ' IN (' . $assocQuery . ') - AND ' . $db->quoteName('asso.master_id') . ' = ' . $db->quote('0') . ')' + AND ' . $db->quoteName('asso.parent_id') . ' = ' . $db->quote('0') . ')' . ')' ); } - // Out of date + // Out-of-date if ($assocStateField === 'out_of_date') { - // If we are on the masterlanguage and we check the state of the children - $query->where('((' . $db->quoteName('asso2.master_id') . ' = ' . $db->quoteName('asso.id') - . ' AND ' . $db->quoteName('asso2.master_date') . ' < ' . $db->quoteName('asso.master_date') . ')' - // Or we are on the child language and we check its state comparing to its master. - . ' OR (' . $db->quoteName('asso.master_date') . ' < ' . $db->quoteName('asso2.master_date') - . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.master_id') . '))' + // If we are on the parent language and we check the state of the children + $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') + . ' AND ' . $db->quoteName('asso2.parent_date') . ' < ' . $db->quoteName('asso.parent_date') . ')' + // Or we are on the child language and we check its state comparing to its parent. + . ' OR (' . $db->quoteName('asso.parent_date') . ' < ' . $db->quoteName('asso2.parent_date') + . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.parent_id') . '))' ); } // Up-to-date if ($assocStateField === 'up_to_date') { - // If we are on the masterlanguage and we check the state of the children - $query->where('((' . $db->quoteName('asso2.master_id') . ' = ' . $db->quoteName('asso.id') - . ' AND ' . $db->quoteName('asso2.master_date') . ' = ' . $db->quoteName('asso.master_date') . ')' - // Or we are on the child language and we check its state comparing to its master. - . ' OR (' . $db->quoteName('asso.master_date') . ' = ' . $db->quoteName('asso2.master_date') - . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.master_id') . '))' + // If we are on the parent language and we check the state of the children + $query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') + . ' AND ' . $db->quoteName('asso2.parent_date') . ' = ' . $db->quoteName('asso.parent_date') . ')' + // Or we are on the child language and we check its state comparing to its parent. + . ' OR (' . $db->quoteName('asso.parent_date') . ' = ' . $db->quoteName('asso2.parent_date') + . ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.parent_id') . '))' ); } } diff --git a/administrator/components/com_associations/Model/AssociationMasterModel.php b/administrator/components/com_associations/Model/DefaultAssocLangModel.php similarity index 68% rename from administrator/components/com_associations/Model/AssociationMasterModel.php rename to administrator/components/com_associations/Model/DefaultAssocLangModel.php index 6b910636db97f..bafcd94f3bfae 100644 --- a/administrator/components/com_associations/Model/AssociationMasterModel.php +++ b/administrator/components/com_associations/Model/DefaultAssocLangModel.php @@ -19,21 +19,21 @@ * * @since 4.0 */ -class AssociationMasterModel extends BaseModel +class DefaultAssocLangModel extends BaseModel { /** - * Update the childs modified date of the master item from #__associations table. + * Update the childs modified date of the parent from #__associations table. * * @param integer $childId The id of the item that gets updated - * @param integer $masterId The associated master item of the child item + * @param integer $parentId The associated parent of the child item * @param string $itemtype The component item type * * @return boolean True on success. * * @since 4.0 */ - public function update($childId, $masterId, $itemtype) + public function update($childId, $parentId, $itemtype) { list($extensionName, $typeName) = explode('.', $itemtype, 2); @@ -43,18 +43,18 @@ public function update($childId, $masterId, $itemtype) $db = Factory::getDbo(); $subQuery = $db->getQuery(true) - ->select($db->quoteName('master_date')) + ->select($db->quoteName('parent_date')) ->from($db->quoteName('#__associations')) - ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)) - ->where($db->quoteName('master_id') . ' = ' . $db->quote(0)) + ->where($db->quoteName('id') . ' = ' . $db->quote($parentId)) + ->where($db->quoteName('parent_id') . ' = ' . $db->quote(0)) ->where($db->quoteName('context') . ' = ' . $db->quote($context)); - $masterModified = $db->setQuery($subQuery)->loadResult(); + $parentModified = $db->setQuery($subQuery)->loadResult(); $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('master_date') . ' = ' . $db->quote($masterModified)) + ->set($db->quoteName('parent_date') . ' = ' . $db->quote($parentModified)) ->where($db->quoteName('id') . ' = ' . $db->quote($childId)) - ->where($db->quoteName('master_id') . ' = ' . $db->quote($masterId)) + ->where($db->quoteName('parent_id') . ' = ' . $db->quote($parentId)) ->where($db->quoteName('context') . ' = ' . $db->quote($context)); $db->setQuery($query); diff --git a/administrator/components/com_associations/View/Association/HtmlView.php b/administrator/components/com_associations/View/Association/HtmlView.php index 7ae9676eed2b6..d56011d70ffcf 100644 --- a/administrator/components/com_associations/View/Association/HtmlView.php +++ b/administrator/components/com_associations/View/Association/HtmlView.php @@ -171,23 +171,23 @@ public function display($tpl = null) $this->targetTitle = AssociationsHelper::getTypeFieldName($extensionName, $typeName, 'title'); $task = $typeName . '.' . $this->targetAction; - // The update layout can only be set when a global master language is used. - // Get version ids of the master item, when versions are enabled. + // The update layout can only be set when a default association language is used. + // Get version ids of the parent, when versions are enabled. if ($this->getLayout() === 'update') { $saveHistory = ComponentHelper::getParams($extensionName)->get('save_history', 0); if ($saveHistory) { - $typeAlias = $typeName === 'category' ? $extensionName . '.' . $typeName : $reference['typeAlias']; - $model = $this->getModel(); - $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); - $masterVersionIds = $model->getMasterCompareValues($referenceId, $this->targetId, $extensionName, $typeName, $typeId); + $typeAlias = $typeName === 'category' ? $extensionName . '.' . $typeName : $reference['typeAlias']; + $model = $this->getModel(); + $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); + $parentVersionIds = $model->getParentCompareValues($referenceId, $this->targetId, $extensionName, $typeName, $typeId); - if ($masterVersionIds[0] !== null && $masterVersionIds[1] !== null) + if ($parentVersionIds[0] !== null && $parentVersionIds[1] !== null) { - $this->referenceVersionIdNew = $masterVersionIds[0]; - $this->referenceVersionIdOld = $masterVersionIds[1]; + $this->referenceVersionIdNew = $parentVersionIds[0]; + $this->referenceVersionIdOld = $parentVersionIds[1]; } } } @@ -232,7 +232,7 @@ protected function addToolbar() $toolbar = Toolbar::getInstance('toolbar'); - // The update layout can only be set when a global master language is used. + // The update layout can only be set when a default association language is used. if ($this->getLayout() === 'update') { // In the update view we can just save the target @@ -242,10 +242,10 @@ protected function addToolbar() . Text::_('COM_ASSOCIATIONS_SAVE_AND_UPDATE_TARGET') . '', 'target' ); - // And when saving the target this button gets activated via js to update the master date for the child + // And when saving the target this button gets activated via js to update the parent's date for the child $toolbar->appendButton( 'Custom', '', 'target' + onclick="Joomla.submitbutton(\'defaultassoclang.update\')">', 'target' ); } else diff --git a/administrator/components/com_associations/View/Associations/HtmlView.php b/administrator/components/com_associations/View/Associations/HtmlView.php index 956a5877758b4..aad6b6802a86d 100644 --- a/administrator/components/com_associations/View/Associations/HtmlView.php +++ b/administrator/components/com_associations/View/Associations/HtmlView.php @@ -151,10 +151,10 @@ public function display($tpl = null) unset($this->activeFilters['language']); unset($this->activeFilters['assocstate']); - // Remove association state filter depending on global master language - $globalMasterLang = Associations::getGlobalMasterLanguage(); + // Remove association state filter depending on default association language + $defaultAssocLang = Associations::getDefaultAssocLang(); - if (!$globalMasterLang) + if (!$defaultAssocLang) { $this->filterForm->removeField('assocstate', 'filter'); } diff --git a/administrator/components/com_associations/forms/filter_associations.xml b/administrator/components/com_associations/forms/filter_associations.xml index 05d634e4983a8..f094d10073c21 100644 --- a/administrator/components/com_associations/forms/filter_associations.xml +++ b/administrator/components/com_associations/forms/filter_associations.xml @@ -12,7 +12,7 @@ !empty($data['options']['formSelector']) ? $data['options']['formSelector'] : '#adminForm', ); -$data['options'] = array_merge($customOptions, $data['options']); - -$globalMasterLang = Associations::getGlobalMasterLanguage(); +$data['options'] = array_merge($customOptions, $data['options']); +$defaultAssocLang = Associations::getDefaultAssocLang(); // Load search tools HTMLHelper::_('searchtools.form', $data['options']['formSelector'], $data['options']); @@ -62,7 +61,7 @@ input->get('forcedLanguage', '', 'cmd') == '') : ?> filterForm->getField('language'); ?> - +
      @@ -74,7 +73,7 @@
      - + filterForm->getField('assocstate'); ?>
      diff --git a/administrator/components/com_associations/tmpl/association/update.php b/administrator/components/com_associations/tmpl/association/update.php index 74e5720417337..4141d64874913 100644 --- a/administrator/components/com_associations/tmpl/association/update.php +++ b/administrator/components/com_associations/tmpl/association/update.php @@ -35,7 +35,7 @@ referenceVersionIdNew)) : ?>

      diff --git a/administrator/components/com_associations/tmpl/associations/default.php b/administrator/components/com_associations/tmpl/associations/default.php index fec863a4039f1..e92c9af9d4964 100644 --- a/administrator/components/com_associations/tmpl/associations/default.php +++ b/administrator/components/com_associations/tmpl/associations/default.php @@ -22,7 +22,7 @@ $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); $canManageCheckin = Factory::getUser()->authorise('core.manage', 'com_checkin'); -$globalMasterLang = Associations::getGlobalMasterLanguage(); +$defaultAssocLang = Associations::getDefaultAssocLang(); $assocState = $this->escape($this->state->get('assocstate')); $iconStates = array( @@ -61,7 +61,7 @@ - + @@ -131,7 +131,7 @@ - + extensionName, $this->typeName, (int) $item->id, $item->language, !$isCheckout, true, $assocState); ?> diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index 70f7e27740ca1..96291125407d5 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -27,7 +27,7 @@ use Joomla\CMS\MVC\Model\AdminModel; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\UCM\UCMType; -use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; +use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; use Joomla\Registry\Registry; use Joomla\String\StringHelper; @@ -632,7 +632,7 @@ public function save($data) } // Get association params before they get deleted - $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, $this->associationsContext); + $assocParentDates = DefaultAssocLangHelper::getParentDates($associations, $this->associationsContext); // Get associationskey for edited item $db = $this->getDbo(); @@ -681,15 +681,15 @@ public function save($data) if (count($associations) > 1) { - // If there is an association item with the globalMasterLanguage, then get its id - $globalMasterLang = Associations::getGlobalMasterLanguage(); - $masterId = $associations[$globalMasterLang] ?? ''; + // If there is an association item with the default association language, then get its id + $defaultAssocLang = Associations::getDefaultAssocLang(); + $parentId = $associations[$defaultAssocLang] ?? ''; // Id of the saved item $dataId = (int) $table->id; - // Get the latest modified date of master item - $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName(), $table->extension . '.category'); + // Get the latest modified date of parent + $parentModified = DefaultAssocLangHelper::getParentModifiedDate($parentId, $table->getTableName(), $table->extension . '.category'); // Adding new association for these items $key = md5(json_encode($associations)); @@ -698,13 +698,13 @@ public function save($data) foreach ($associations as $id) { - $masterIdAndDateValues = MasterAssociationsHelper::getMasterValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $oldKey); - $masterIdValue = $masterIdAndDateValues[0]; - $masterDateValue = $masterIdAndDateValues[1] === 'NULL' ? $masterIdAndDateValues[1] : $db->quote($masterIdAndDateValues[1]); + $parentIdAndDateValues = DefaultAssocLangHelper::getParentValues($id, $dataId, $parentId, $parentModified, $assocParentDates, $oldKey); + $parentIdValue = $parentIdAndDateValues[0]; + $parentDateValue = $parentIdAndDateValues[1] === 'NULL' ? $parentIdAndDateValues[1] : $db->quote($parentIdAndDateValues[1]); $query->values( ((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' - . $db->quote($masterIdValue) . ',' . $masterDateValue + . $db->quote($parentIdValue) . ',' . $parentDateValue ); } diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index afbbd031567e2..2b45788c46b16 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -16,7 +16,7 @@ use Joomla\CMS\Language\Associations; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; -use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; +use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; use Joomla\Utilities\ArrayHelper; @@ -42,7 +42,7 @@ public function association($catid, $extension = 'com_content') { // Defaults $html = ''; - $globalMasterLang = Associations::getGlobalMasterLanguage(); + $defaultAssocLang = Associations::getDefaultAssocLang(); // Check if versions are enabled. $saveHistory = ComponentHelper::getParams($extension)->get('save_history', 0); @@ -61,8 +61,8 @@ public function association($catid, $extension = 'com_content') ->from('#__categories as c') ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); - // Don't get the id of the item itself when there is no master language used. - if (!$globalMasterLang) + // Don't get the id of the item itself when there is no default association language used. + if (!$defaultAssocLang) { $query->where('c.id != ' . $catid); } @@ -81,76 +81,76 @@ public function association($catid, $extension = 'com_content') throw new \Exception($e->getMessage(), 500, $e); } - if ($globalMasterLang) + if ($defaultAssocLang) { - // Check if the current item is a master item. - $isMaster = (array_key_exists($catid, $items) && ($items[$catid]->lang_code === $globalMasterLang)) + // Check if the current item is a parent. + $isParent = (array_key_exists($catid, $items) && ($items[$catid]->lang_code === $defaultAssocLang)) ? true : false; - // Check if there is a master item in the association and get its id if so. - $masterId = array_key_exists($globalMasterLang, $associations) - ? $associations[$globalMasterLang] + // Check if there is a parent in the association and get its id if so. + $parentId = array_key_exists($defaultAssocLang, $associations) + ? $associations[$defaultAssocLang] : ''; - // Get master dates of each item of associations. - $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_categories.item'); + // Get parent dates of each item of associations. + $assocParentDates = DefaultAssocLangHelper::getParentDates($associations, 'com_categories.item'); } if ($items) { foreach ($items as $key => &$item) { - $labelClass = 'badge-success'; - $masterInfo = ''; - $url = Route::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); + $labelClass = 'badge-success'; + $parentChildInfo = ''; + $url = Route::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); - if ($globalMasterLang) + if ($defaultAssocLang) { - // Don't continue for master, because it has been set here before. - if ($key === 'master') + // Don't continue for parent, because it has been set here before. + if ($key === 'parent') { continue; } - $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos( - $catid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory + $classParentInfoItems = DefaultAssocLangHelper::setParentAndChildInfos( + $catid, $items, $key, $item, $defaultAssocLang, $isParent, $parentId, $assocParentDates, $saveHistory ); - $labelClass = $classMasterInfoItems[0]; - $masterInfo = $classMasterInfoItems[1]; - $items = $classMasterInfoItems[2]; - $needsUpdate = $classMasterInfoItems[3]; + $labelClass = $classParentInfoItems[0]; + $parentChildInfo = $classParentInfoItems[1]; + $items = $classParentInfoItems[2]; + $needsUpdate = $classParentInfoItems[3]; $url = Route::_( - MasterAssociationsHelper::getAssociationUrl( - $item->id, $globalMasterLang, $extension . '.category', $item->lang_code, $key, $masterId, $needsUpdate + DefaultAssocLangHelper::getAssociationUrl( + $item->id, $defaultAssocLang, $extension . '.category', $item->lang_code, $key, $parentId, $needsUpdate ) ); } $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' - . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . $masterInfo; + . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . $parentChildInfo; $classes = 'badge ' . $labelClass; $item->link = '' . $text . '' . ''; - // Reorder the array, so the master item gets to the first place. - if ($item->lang_code === $globalMasterLang) + // Reorder the array, so the parent gets to the first place. + if ($item->lang_code === $defaultAssocLang) { - $items = array('master' => $items[$key]) + $items; + $items = array('parent' => $items[$key]) + $items; unset($items[$key]); } } - // If a master item doesn't exist, display that there is no association with the master language. - if ($globalMasterLang && !$masterId) + // If a parent doesn't exist, display that there is no association with the default association language. + if ($defaultAssocLang && !$parentId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $catid, $extension . '.category'); + $link = DefaultAssocLangHelper::addNotAssociatedParentLink($defaultAssocLang, $catid, $extension . '.category'); // Add this on the top of the array. - $items = array('master' => array('link' => $link)) + $items; + $items = array('parent' => array('link' => $link)) + $items; } } diff --git a/administrator/components/com_categories/tmpl/categories/default.php b/administrator/components/com_categories/tmpl/categories/default.php index 0f5868a0568b6..756f743ec2a08 100644 --- a/administrator/components/com_categories/tmpl/categories/default.php +++ b/administrator/components/com_categories/tmpl/categories/default.php @@ -30,7 +30,7 @@ $parts = explode('.', $extension, 2); $component = $parts[0]; $section = null; -$masterAlign = Associations::getGlobalMasterLanguage() ? 'text-center ' : ''; +$assocAlign = Associations::getDefaultAssocLang() ? 'text-center ' : ''; if (count($parts) > 1) { @@ -110,7 +110,7 @@ assoc) : ?> - + diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index 0cdb53e55f94c..aa0ce75417c11 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -17,7 +17,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; -use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; +use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; use Joomla\Utilities\ArrayHelper; /** @@ -40,7 +40,7 @@ public function association($contactid) { // Defaults $html = ''; - $globalMasterLang = Associations::getGlobalMasterLanguage(); + $defaultAssocLang = Associations::getDefaultAssocLang(); // Check if versions are enabled $saveHistory = ComponentHelper::getParams('com_contact')->get('save_history', 0); @@ -63,8 +63,8 @@ public function association($contactid) ->join('LEFT', '#__categories as cat ON cat.id=c.catid') ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); - // Don't get the id of the item itself when there is no master language used. - if (!$globalMasterLang) + // Don't get the id of the item itself when there is no default association language used. + if (!$defaultAssocLang) { $query->where('c.id != ' . $contactid); } @@ -83,76 +83,76 @@ public function association($contactid) throw new \Exception($e->getMessage(), 500, $e); } - if ($globalMasterLang) + if ($defaultAssocLang) { - // Check if current item is the master item. - $isMaster = (array_key_exists($contactid, $items) && ($items[$contactid]->lang_code === $globalMasterLang)) + // Check if current item is the parent. + $isParent = (array_key_exists($contactid, $items) && ($items[$contactid]->lang_code === $defaultAssocLang)) ? true : false; - // Check if there is a master item in the association and get its id if so. - $masterId = array_key_exists($globalMasterLang, $associations) - ? $associations[$globalMasterLang] + // Check if there is a parent in the association and get its id if so. + $parentId = array_key_exists($defaultAssocLang, $associations) + ? $associations[$defaultAssocLang] : ''; - // Get master dates of each item of associations. - $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_contact.item'); + // Get parent dates of each item of associations. + $assocParentDates = DefaultAssocLangHelper::getParentDates($associations, 'com_contact.item'); } if ($items) { foreach ($items as $key => &$item) { - $masterInfo = ''; - $labelClass = 'badge-success'; - $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); + $parentChildInfo = ''; + $labelClass = 'badge-success'; + $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); - if ($globalMasterLang) + if ($defaultAssocLang) { - // Don't continue for master, because it has been set just before as new array item - if ($key === 'master') + // Don't continue for parent, because it has been set just before as new array item + if ($key === 'parent') { continue; } - $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos( - $contactid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory + $classParentInfoItems = DefaultAssocLangHelper::setParentAndChildInfos( + $contactid, $items, $key, $item, $defaultAssocLang, $isParent, $parentId, $assocParentDates, $saveHistory ); - $labelClass = $classMasterInfoItems[0]; - $masterInfo = $classMasterInfoItems[1]; - $items = $classMasterInfoItems[2]; - $needsUpdate = $classMasterInfoItems[3]; + $labelClass = $classParentInfoItems[0]; + $parentChildInfo = $classParentInfoItems[1]; + $items = $classParentInfoItems[2]; + $needsUpdate = $classParentInfoItems[3]; $url = Route::_( - MasterAssociationsHelper::getAssociationUrl( - $item->id, $globalMasterLang, 'com_contact.contact', $item->lang_code, $key, $masterId, $needsUpdate + DefaultAssocLangHelper::getAssociationUrl( + $item->id, $defaultAssocLang, 'com_contact.contact', $item->lang_code, $key, $parentId, $needsUpdate ) ); } $text = strtoupper($item->lang_sef); $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' - . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; + . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $parentChildInfo; $classes = 'badge ' . $labelClass; $item->link = '' . $text . '' . ''; - // Reorder the array, so the master item gets to the first place - if ($item->lang_code === $globalMasterLang) + // Reorder the array, so the parent gets to the first place + if ($item->lang_code === $defaultAssocLang) { - $items = array('master' => $items[$key]) + $items; + $items = array('parent' => $items[$key]) + $items; unset($items[$key]); } } - // If a master item doesn't exist, display that there is no association with the master language - if ($globalMasterLang && !$masterId) + // If a parent doesn't exist, display that there is no association with the default association language. + if ($defaultAssocLang && !$parentId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $contactid, 'com_contact.contact'); + $link = DefaultAssocLangHelper::addNotAssociatedParentLink($defaultAssocLang, $contactid, 'com_contact.contact'); // Add this on the top of the array - $items = array('master' => array('link' => $link)) + $items; + $items = array('parent' => array('link' => $link)) + $items; } } diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index 97675ced743b5..2f212eda9c6ca 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -17,7 +17,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; -use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; +use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; use Joomla\Utilities\ArrayHelper; /** @@ -41,7 +41,7 @@ public function association($articleid) { // Defaults $html = ''; - $globalMasterLang = Associations::getGlobalMasterLanguage(); + $defaultAssocLang = Associations::getDefaultAssocLang(); // Check if versions are enabled $saveHistory = ComponentHelper::getParams('com_content')->get('save_history', 0); @@ -65,8 +65,8 @@ public function association($articleid) ->join('LEFT', '#__categories as cat ON cat.id=c.catid') ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); - // Don't get the id of the item itself when there is no master language used - if (!$globalMasterLang) + // Don't get the id of the item itself when there is no default association language used. + if (!$defaultAssocLang) { $query->where('c.id != ' . $articleid); } @@ -85,76 +85,76 @@ public function association($articleid) throw new \Exception($e->getMessage(), 500, $e); } - if ($globalMasterLang) + if ($defaultAssocLang) { - // Check if the current item is a master item. - $isMaster = (array_key_exists($articleid, $items) && ($items[$articleid]->lang_code === $globalMasterLang)) + // Check if the current item is a parent. + $isParent = (array_key_exists($articleid, $items) && ($items[$articleid]->lang_code === $defaultAssocLang)) ? true : false; - // Check if there is a master item in the association and get its id if so - $masterId = array_key_exists($globalMasterLang, $associations) - ? $associations[$globalMasterLang] + // Check if there is a parent in the association and get its id if so + $parentId = array_key_exists($defaultAssocLang, $associations) + ? $associations[$defaultAssocLang] : ''; - // Get master dates of each item of associations. - $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_content.item'); + // Get parent dates of each item of associations. + $assocParentDates = DefaultAssocLangHelper::getParentDates($associations, 'com_content.item'); } if ($items) { foreach ($items as $key => &$item) { - $masterInfo = ''; - $labelClass = 'badge-success'; - $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); + $parentChildInfo = ''; + $labelClass = 'badge-success'; + $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); - if ($globalMasterLang) + if ($defaultAssocLang) { - // Don't continue for master, because it has been set here before - if ($key === 'master') + // Don't continue for parent, because it has been set here before + if ($key === 'parent') { continue; } - $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos( - $articleid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory + $classParentInfoItems = DefaultAssocLangHelper::setParentAndChildInfos( + $articleid, $items, $key, $item, $defaultAssocLang, $isParent, $parentId, $assocParentDates, $saveHistory ); - $labelClass = $classMasterInfoItems[0]; - $masterInfo = $classMasterInfoItems[1]; - $items = $classMasterInfoItems[2]; - $needsUpdate = $classMasterInfoItems[3]; + $labelClass = $classParentInfoItems[0]; + $parentChildInfo = $classParentInfoItems[1]; + $items = $classParentInfoItems[2]; + $needsUpdate = $classParentInfoItems[3]; $url = Route::_( - MasterAssociationsHelper::getAssociationUrl( - $item->id, $globalMasterLang, 'com_content.article', $item->lang_code, $key, $masterId, $needsUpdate + DefaultAssocLangHelper::getAssociationUrl( + $item->id, $defaultAssocLang, 'com_content.article', $item->lang_code, $key, $parentId, $needsUpdate ) ); } $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' - . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; + . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $parentChildInfo; $classes = 'badge ' . $labelClass; $item->link = '' . $text . '' . ''; - // Reorder the array, so the master item gets to the first place - if ($item->lang_code === $globalMasterLang) + // Reorder the array, so the parent gets to the first place + if ($item->lang_code === $defaultAssocLang) { - $items = array('master' => $items[$key]) + $items; + $items = array('parent' => $items[$key]) + $items; unset($items[$key]); } } - // If a master item doesn't exist, display that there is no association with the master language - if ($globalMasterLang && !$masterId) + // If a parent doesn't exist, display that there is no association with the default association language. + if ($defaultAssocLang && !$parentId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $articleid, 'com_content.article'); + $link = DefaultAssocLangHelper::addNotAssociatedParentLink($defaultAssocLang, $articleid, 'com_content.article'); // Add this on the top of the array - $items = array('master' => array('link' => $link)) + $items; + $items = array('parent' => array('link' => $link)) + $items; } } diff --git a/administrator/components/com_contenthistory/tmpl/compare/comparemaster.php b/administrator/components/com_contenthistory/tmpl/compare/compareassocparent.php similarity index 96% rename from administrator/components/com_contenthistory/tmpl/compare/comparemaster.php rename to administrator/components/com_contenthistory/tmpl/compare/compareassocparent.php index 2af62b6ddd08c..82317cf975fe9 100644 --- a/administrator/components/com_contenthistory/tmpl/compare/comparemaster.php +++ b/administrator/components/com_contenthistory/tmpl/compare/compareassocparent.php @@ -31,7 +31,7 @@ } HTMLHelper::_('script', 'vendor/diff/diff.min.js', array('version' => 'auto', 'relative' => true)); -HTMLHelper::_('script', 'com_associations/admin-compare-master.min.js', array('version' => 'auto', 'relative' => true)); +HTMLHelper::_('script', 'com_associations/admin-compare-assoc-parent.min.js', array('version' => 'auto', 'relative' => true)); HTMLHelper::_('stylesheet', 'com_associations/sidebyside.css', ['version' => 'auto', 'relative' => true]); ?> diff --git a/administrator/components/com_menus/Model/ItemModel.php b/administrator/components/com_menus/Model/ItemModel.php index 1b14135ec2174..ba1bb2497e27b 100644 --- a/administrator/components/com_menus/Model/ItemModel.php +++ b/administrator/components/com_menus/Model/ItemModel.php @@ -1580,9 +1580,9 @@ public function save($data) if (count($associations) > 1) { - // If there is an associated item with the globalMasterLanguage, get its id. - $globalMasterLang = Associations::getGlobalMasterLanguage(); - $masterId = $associations[$globalMasterLang] ?? ''; + // If there is an associated item with the default association language, get its id. + $defaultAssocLang = Associations::getDefaultAssocLang(); + $parentId = $associations[$defaultAssocLang] ?? ''; // Adding new association for these items $key = md5(json_encode($associations)); @@ -1591,12 +1591,12 @@ public function save($data) foreach ($associations as $id) { - // If there is no master item in this association, then reset the master id. - // Otherwise, if the associated item is a master item, set its master id to 0, otherwise to the master Id. - $masterIdValue = $masterId ? ($masterId === $id ? 0 : $masterId) : -1; + // If there is no parent in this association, then reset the parent id. + // Otherwise, if the associated item is a parent, set its parent id to 0, otherwise to the parent Id. + $parentIdValue = $parentId ? ($parentId === $id ? 0 : $parentId) : -1; $query->values( ((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) - . ',' . $db->quote($masterIdValue) . ', NULL' + . ',' . $db->quote($parentIdValue) . ', NULL' ); } diff --git a/administrator/components/com_menus/Service/HTML/Menus.php b/administrator/components/com_menus/Service/HTML/Menus.php index a00b3508df350..83cb9c2b21cd9 100644 --- a/administrator/components/com_menus/Service/HTML/Menus.php +++ b/administrator/components/com_menus/Service/HTML/Menus.php @@ -16,7 +16,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; -use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; +use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; use Joomla\Component\Menus\Administrator\Helper\MenusHelper; use Joomla\Registry\Registry; @@ -44,7 +44,7 @@ public function association($itemid) { // Defaults $html = ''; - $globalMasterLang = Associations::getGlobalMasterLanguage(); + $defaultAssocLang = Associations::getDefaultAssocLang(); // Get the associations if ($associations = MenusHelper::getAssociations($itemid)) @@ -59,8 +59,8 @@ public function association($itemid) ->join('LEFT', '#__menu_types as mt ON mt.menutype=m.menutype') ->where('m.id IN (' . implode(',', array_values($associations)) . ')'); - // Don't get the id of the item itself when there is no master language used - if (!$globalMasterLang) + // Don't get the id of the item itself when there is no default association language used + if (!$defaultAssocLang) { $query->where('m.id != ' . $itemid); } @@ -79,16 +79,16 @@ public function association($itemid) throw new \Exception($e->getMessage(), 500); } - if ($globalMasterLang) + if ($defaultAssocLang) { - // Check if current item is the master item. - $isMaster = (array_key_exists($itemid, $items) && ($items[$itemid]->lang_code === $globalMasterLang)) + // Check if current item is the parent. + $isParent = (array_key_exists($itemid, $items) && ($items[$itemid]->lang_code === $defaultAssocLang)) ? true : false; - // Check if there is a master item in the association and get its id if so - $masterId = array_key_exists($globalMasterLang, $associations) - ? $associations[$globalMasterLang] + // Check if there is a parent in the association and get its id if so + $parentId = array_key_exists($defaultAssocLang, $associations) + ? $associations[$defaultAssocLang] : ''; } @@ -97,56 +97,56 @@ public function association($itemid) { foreach ($items as $key => &$item) { - $masterInfo = ''; + $parentChildInfo = ''; $classes = 'badge badge-success'; $url = Route::_('index.php?option=com_menus&task=item.edit&id=' . (int) $item->id); - if ($globalMasterLang) + if ($defaultAssocLang) { - // Don't continue for master, because it has been set here before - if ($key === 'master') + // Don't continue for parent, because it has been set here before + if ($key === 'parent') { continue; } - // Don't display other children if the current item is a child of the master language. - if ($key !== $itemid && $globalMasterLang !== $item->lang_code && !$isMaster) + // Don't display other children if the current item is a child. + if ($key !== $itemid && $defaultAssocLang !== $item->lang_code && !$isParent) { unset($items[$key]); } - if ($key === $masterId) + if ($key === $parentId) { - $classes .= ' master-item'; - $masterInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_MASTER_ITEM'); + $classes .= ' parent-item'; + $parentChildInfo = '

      ' . Text::_('JGLOBAL_ASSOCIATIONS_DEFAULT_ASSOC_LANG_ITEM'); } - $url = Route::_(MasterAssociationsHelper::getAssociationUrl($item->id, $globalMasterLang, 'com_menus.item', $item->lang_code, $key, $masterId)); + $url = Route::_(DefaultAssocLangHelper::getAssociationUrl($item->id, $defaultAssocLang, 'com_menus.item', $item->lang_code, $key, $parentId)); } $text = strtoupper($item->lang_sef); $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('COM_MENUS_MENU_SPRINTF', $item->menu_title) - . $masterInfo; + . $parentChildInfo; $item->link = '' . $text . '' . ''; - // Reorder the array, so the master item gets to the first place - if ($item->lang_code === $globalMasterLang) + // Reorder the array, so the parent gets to the first place + if ($item->lang_code === $defaultAssocLang) { - $items = array('master' => $items[$key]) + $items; + $items = array('parent' => $items[$key]) + $items; unset($items[$key]); } } - // If a master item doesn't exist, display that there is no association with the master language - if ($globalMasterLang && !$masterId) + // If a parent doesn't exist, display that there is no association with the default association language. + if ($defaultAssocLang && !$parentId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $itemid, 'com_menus.item'); + $link = DefaultAssocLangHelper::addNotAssociatedParentLink($defaultAssocLang, $itemid, 'com_menus.item'); // Add this on the top of the array - $items = array('master' => array('link' => $link)) + $items; + $items = array('parent' => array('link' => $link)) + $items; } } diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index 402929f24eba6..686f5d3527109 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -17,7 +17,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; -use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; +use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; /** * Utility class for creating HTML Grids. @@ -39,7 +39,7 @@ public function association($newsfeedid) { // Defaults $html = ''; - $globalMasterLang = Associations::getGlobalMasterLanguage(); + $defaultAssocLang = Associations::getDefaultAssocLang(); // Check if versions are enabled $saveHistory = ComponentHelper::getParams('com_newsfeeds')->get('save_history', 0); @@ -62,8 +62,8 @@ public function association($newsfeedid) ->join('LEFT', '#__categories as cat ON cat.id=c.catid') ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); - // Don't get the id of the item itself when there is no master language used - if (!$globalMasterLang) + // Don't get the id of the item itself when there is no default association language used + if (!$defaultAssocLang) { $query->where('c.id != ' . $newsfeedid); } @@ -82,76 +82,76 @@ public function association($newsfeedid) throw new \Exception($e->getMessage(), 500); } - if ($globalMasterLang) + if ($defaultAssocLang) { - // Check if current item is a master item. - $isMaster = (array_key_exists($newsfeedid, $items) && ($items[$newsfeedid]->lang_code === $globalMasterLang)) + // Check if current item is a parent. + $isParent = (array_key_exists($newsfeedid, $items) && ($items[$newsfeedid]->lang_code === $defaultAssocLang)) ? true : false; - // Check if there is a master item in the association and get its id if so. - $masterId = array_key_exists($globalMasterLang, $associations) - ? $associations[$globalMasterLang] + // Check if there is a parent in the association and get its id if so. + $parentId = array_key_exists($defaultAssocLang, $associations) + ? $associations[$defaultAssocLang] : ''; - // Get master dates of each item of associations. - $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, 'com_newsfeeds.item'); + // Get parent dates of each item of associations. + $assocParentDates = DefaultAssocLangHelper::getParentDates($associations, 'com_newsfeeds.item'); } if ($items) { foreach ($items as $key => &$item) { - $masterInfo = ''; + $parentChildInfo = ''; $labelClass = 'badge-success'; $url = Route::_('index.php?option=com_newsfeeds&task=newsfeed.edit&id=' . (int) $item->id); - if ($globalMasterLang) + if ($defaultAssocLang) { - // Don't continue for master, because it has been set here before - if ($key === 'master') + // Don't continue for parent, because it has been set here before + if ($key === 'parent') { continue; } - $classMasterInfoItems = MasterAssociationsHelper::setMasterAndChildInfos( - $newsfeedid, $items, $key, $item, $globalMasterLang, $isMaster, $masterId, $assocMasterDates, $saveHistory + $classParentInfoItems = DefaultAssocLangHelper::setParentAndChildInfos( + $newsfeedid, $items, $key, $item, $defaultAssocLang, $isParent, $parentId, $assocParentDates, $saveHistory ); - $labelClass = $classMasterInfoItems[0]; - $masterInfo = $classMasterInfoItems[1]; - $items = $classMasterInfoItems[2]; - $needsUpdate = $classMasterInfoItems[3]; + $labelClass = $classParentInfoItems[0]; + $parentChildInfo = $classParentInfoItems[1]; + $items = $classParentInfoItems[2]; + $needsUpdate = $classParentInfoItems[3]; $url = Route::_( - MasterAssociationsHelper::getAssociationUrl( - $item->id, $globalMasterLang, 'com_newsfeeds.newsfeed', $item->lang_code, $key, $masterId, $needsUpdate + DefaultAssocLangHelper::getAssociationUrl( + $item->id, $defaultAssocLang, 'com_newsfeeds.newsfeed', $item->lang_code, $key, $parentId, $needsUpdate ) ); } $text = strtoupper($item->lang_sef); $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
      ' - . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $masterInfo; + . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
      ' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title) . $parentChildInfo; $classes = 'badge ' . $labelClass; $item->link = '' . $text . '' . ''; - // Reorder the array, so the master item gets to the first place - if ($item->lang_code === $globalMasterLang) + // Reorder the array, so the parent gets to the first place + if ($item->lang_code === $defaultAssocLang) { - $items = array('master' => $items[$key]) + $items; + $items = array('parent' => $items[$key]) + $items; unset($items[$key]); } } - // If a master item doesn't exist, display that there is no association with the master language - if ($globalMasterLang && !$masterId) + // If a parent doesn't exist, display that there is no association with the default association language. + if ($defaultAssocLang && !$parentId) { - $link = MasterAssociationsHelper::addNotAssociatedMasterLink($globalMasterLang, $newsfeedid, 'com_newsfeeds.newsfeed'); + $link = DefaultAssocLangHelper::addNotAssociatedParentLink($defaultAssocLang, $newsfeedid, 'com_newsfeeds.newsfeed'); // Add this on the top of the array - $items = array('master' => array('link' => $link)) + $items; + $items = array('parent' => array('link' => $link)) + $items; } } diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index cc35b2afbbed9..42746f785484e 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -48,7 +48,7 @@ COM_ASSOCIATIONS_SELECT_MENU="- Select Menu -" COM_ASSOCIATIONS_SELECT_TARGET="Select Target" COM_ASSOCIATIONS_SELECT_TARGET_LANGUAGE="- Select Target Language -" COM_ASSOCIATIONS_STATE_NOT_ASSOCIATED="Not Associated" -COM_ASSOCIATIONS_STATE_OUT_OF_DATE="Out of date" +COM_ASSOCIATIONS_STATE_OUT_OF_DATE="Out-of-date" COM_ASSOCIATIONS_STATE_UP_TO_DATE="Up-to-date" COM_ASSOCIATIONS_TABLE_CAPTION="Table of Associations" COM_ASSOCIATIONS_TITLE="Associations" diff --git a/administrator/language/en-GB/en-GB.ini b/administrator/language/en-GB/en-GB.ini index d98ea4ac33077..ddbe70a425246 100644 --- a/administrator/language/en-GB/en-GB.ini +++ b/administrator/language/en-GB/en-GB.ini @@ -272,8 +272,8 @@ JGLOBAL_ARTICLE_ORDER_DESC="The order that articles will show in." JGLOBAL_ARTICLE_ORDER_LABEL="Article Order" JGLOBAL_ARTICLES="Articles" JGLOBAL_ASSOC_NOT_POSSIBLE="To define associations, please make sure the item language is not set to 'All'." -JGLOBAL_ASSOCIATIONS_MASTER_LANGUAGE="Master" -JGLOBAL_ASSOCIATIONS_MASTER_ITEM="The master language" +JGLOBAL_ASSOCIATIONS_DEFAULT_ASSOC_LANG="Default Association Language" +JGLOBAL_ASSOCIATIONS_DEFAULT_ASSOC_LANG_ITEM="The Default Association Language" JGLOBAL_ASSOCIATIONS_NEW_ITEM_WARNING="To create associations, first save the item." JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON="Propagate" JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED="Failed propagating associations. You may have to select or create them manually." @@ -282,10 +282,10 @@ JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE="No associations exist to propagate. JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME="Associations have been set for: %s" JGLOBAL_ASSOCIATIONS_PROPAGATE_TIP="Propagates this item's existing associations." JGLOBAL_ASSOCIATIONS_RESET_WARNING="The language has been changed. If you save this item again it will reset the available associations. If this was not intended, close the item." -JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUT_OF_DATE_DESC="This item might be out of date with the master article." -JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC="There is no association for the master language." -JGLOBAL_ASSOCIATIONS_STATE_OUT_OF_DATE_DESC="This item is out of date with the master item." -JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC="This item is up-to-date with the master item." +JGLOBAL_ASSOCIATIONS_STATE_MIGHT_BE_OUT_OF_DATE_DESC="This item might be out-of-date with the item in the default association language." +JGLOBAL_ASSOCIATIONS_STATE_NOT_ASSOCIATED_DESC="There is no association for the default association language." +JGLOBAL_ASSOCIATIONS_STATE_OUT_OF_DATE_DESC="This item is out-of-date with the item in the default association language." +JGLOBAL_ASSOCIATIONS_STATE_UP_TO_DATE_DESC="This item is up-to-date with the item in the default association language." JGLOBAL_AUTH_ACCESS_DENIED="Access Denied" JGLOBAL_AUTH_ACCESS_GRANTED="Access Granted" JGLOBAL_AUTH_BIND_FAILED="Failed binding to LDAP server" diff --git a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini index 3360e265dcb6c..358963750ab50 100644 --- a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini +++ b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini @@ -9,11 +9,11 @@ PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_LABEL="Add Alternate Meta Tags" PLG_SYSTEM_LANGUAGEFILTER_FIELD_AUTOMATIC_CHANGE_LABEL="Automatic Language Change" PLG_SYSTEM_LANGUAGEFILTER_FIELD_COOKIE_LABEL="Cookie Lifetime" PLG_SYSTEM_LANGUAGEFILTER_FIELD_DETECT_BROWSER_LABEL="Language Selection for new Visitors" -PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_LABEL="Global Master Language" -PLG_SYSTEM_LANGUAGEFILTER_FIELD_GLOBAL_MASTER_LANGUAGE_DESC="Note that changing this value will overwrite all existing Master Child relationships with their association states." +PLG_SYSTEM_LANGUAGEFILTER_FIELD_DEFAULT_ASSOC_LANG_LABEL="Default Association Language" +PLG_SYSTEM_LANGUAGEFILTER_FIELD_DEFAULT_ASSOC_LANG_DESC="Note that changing this value will overwrite all existing parent-child relationships with their association states." PLG_SYSTEM_LANGUAGEFILTER_FIELD_ITEM_ASSOCIATIONS_LABEL="Item Associations" -PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_LABEL="Set a Master Language?" -PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_MASTER_LANGUAGE_DESC="When enabled, a master-child relationship is added between the languages. This adds an additional 'out of date' association state to a child item depending on its master. Enable versions to get a comparison view for out of date items. If this field is disabled, functions dependent on this data are not available." +PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_DEFAULT_ASSOC_LANG_LABEL="Set a Default Association Language?" +PLG_SYSTEM_LANGUAGEFILTER_FIELD_USE_DEFAULT_ASSOC_LANG_DESC="When enabled, a parent-child relationship is added between the languages. This adds additional 'out-of-date' and 'up-to-date' association state to a child depending on its parent. Enable versions to get a comparison view for out-of-date items. If this field is disabled, functions dependent on this data are not available." PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LABEL="Add x-default Meta Tag" PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LANGUAGE_LABEL="x-default Language" PLG_SYSTEM_LANGUAGEFILTER_OPTION_DEFAULT_LANGUAGE="Default frontend language" diff --git a/administrator/templates/atum/scss/template.scss b/administrator/templates/atum/scss/template.scss index 6be5e22053f62..e6a79d98d8579 100644 --- a/administrator/templates/atum/scss/template.scss +++ b/administrator/templates/atum/scss/template.scss @@ -114,7 +114,7 @@ padding: 0; } - &.master { + &.parent { text-align: center; div[role="tooltip"] { @@ -127,7 +127,7 @@ margin-bottom: 0.2rem; } - .master-language { + .parent-language { & > a { border-radius: 0; diff --git a/build/media_source/com_associations/js/admin-compare-master.es6.js b/build/media_source/com_associations/js/admin-compare-assoc-parent.es6.js similarity index 100% rename from build/media_source/com_associations/js/admin-compare-master.es6.js rename to build/media_source/com_associations/js/admin-compare-assoc-parent.es6.js diff --git a/build/media_source/com_associations/js/sidebysideupdate.es6.js b/build/media_source/com_associations/js/sidebysideupdate.es6.js index eeed79df97a6c..6b25c5beadca3 100644 --- a/build/media_source/com_associations/js/sidebysideupdate.es6.js +++ b/build/media_source/com_associations/js/sidebysideupdate.es6.js @@ -16,7 +16,7 @@ Joomla = window.Joomla || {}; // Using close button, normal joomla submit. if (task === 'association.cancel') { Joomla.submitform(task); - } else if (task === 'associationmaster.update') { + } else if (task === 'defaultassoclang.update') { Joomla.submitform(task); } else { window.frames['target-association'].Joomla.submitbutton(`${document.getElementById('adminForm').getAttribute('data-associatedview')}, .apply`); diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index 97f07d47238d7..1eb63419b5cd6 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -107,8 +107,8 @@ CREATE TABLE IF NOT EXISTS `#__associations` ( `id` int(11) NOT NULL COMMENT 'A reference to the associated item.', `context` varchar(50) NOT NULL COMMENT 'The context of the associated item.', `key` char(32) NOT NULL COMMENT 'The key for the association computed from an md5 on associated ids.', - `master_id` int(11) NOT NULL DEFAULT -1 COMMENT 'The master item of an association.', - `master_date` datetime COMMENT 'The save or modified date of the master item.', + `parent_id` int(11) NOT NULL DEFAULT -1 COMMENT 'The parent of an association.', + `parent_date` datetime COMMENT 'The save or modified date of the parent.', PRIMARY KEY (`context`,`id`), KEY `idx_key` (`key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index 885ca3485cc82..c433f041c3c1c 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -111,8 +111,8 @@ CREATE TABLE IF NOT EXISTS "#__associations" ( "id" int NOT NULL, "context" varchar(50) NOT NULL, "key" char(32) NOT NULL, - "master_id" integer DEFAULT -1 NOT NULL, - "master_date" timestamp without time zone, + "parent_id" integer DEFAULT -1 NOT NULL, + "parent_date" timestamp without time zone, CONSTRAINT "#__associations_idx_context_id" PRIMARY KEY ("context", "id") ); CREATE INDEX "#__associations_idx_key" ON "#__associations" ("key"); @@ -120,8 +120,8 @@ CREATE INDEX "#__associations_idx_key" ON "#__associations" ("key"); COMMENT ON COLUMN "#__associations"."id" IS 'A reference to the associated item.'; COMMENT ON COLUMN "#__associations"."context" IS 'The context of the associated item.'; COMMENT ON COLUMN "#__associations"."key" IS 'The key for the association computed from an md5 on associated ids.'; -COMMENT ON COLUMN "#__associations"."master_id" IS 'The master item of an association.'; -COMMENT ON COLUMN "#__associations"."master_date" IS 'The save or modified date of the master item.'; +COMMENT ON COLUMN "#__associations"."parent_id" IS 'The parent of an association.'; +COMMENT ON COLUMN "#__associations"."parent_date" IS 'The save or modified date of the parent.'; -- -- Table structure for table `#__banners` diff --git a/installation/src/Model/LanguagesModel.php b/installation/src/Model/LanguagesModel.php index 7e75d4505ce28..61f80d89d18e5 100644 --- a/installation/src/Model/LanguagesModel.php +++ b/installation/src/Model/LanguagesModel.php @@ -1406,22 +1406,22 @@ public function addBlogMenuItem($itemLanguage, $categoryId) public function addAssociations($groupedAssociations) { $db = Factory::getDbo(); - $globalMasterLang = Associations::getGlobalMasterLanguage(); + $defaultAssocLang = Associations::getDefaultAssocLang(); foreach ($groupedAssociations as $context => $associations) { - // If there is an association item with the globalMasterLanguage, get its id. - $masterId = $associations[$globalMasterLang] ?? ''; - $key = md5(json_encode($associations)); - $query = $db->getQuery(true) + // If there is an association item with the default association language, get its id. + $parentId = $associations[$defaultAssocLang] ?? ''; + $key = md5(json_encode($associations)); + $query = $db->getQuery(true) ->insert('#__associations'); foreach ($associations as $language => $id) { - // If there is no master item in this association, then reset the master_id to -1 - // Otherwise, if the association item is a master item set the master_id to 0, otherwise to the masterId. - $masterIdValue = $masterId ? ($masterId === $id ? 0 : $masterId) : -1; - $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($masterIdValue) . ', NULL'); + // If there is no parent within this association, then reset the parent_id to -1 + // Otherwise, if the associated item is a parent set the parent_id to 0, otherwise to the parentId. + $parentIdValue = $parentId ? ($parentId === $id ? 0 : $parentId) : -1; + $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($parentIdValue) . ', NULL'); } $db->setQuery($query); diff --git a/layouts/joomla/content/associations.php b/layouts/joomla/content/associations.php index c03e7c80aff15..f61a0ce4653f6 100644 --- a/layouts/joomla/content/associations.php +++ b/layouts/joomla/content/associations.php @@ -12,14 +12,14 @@ $items = $displayData; if (!empty($items)) : ?> - -
        -
      • + +
          +
        • link; ?>
            $item) : ?> - +
          • link; ?>
          • diff --git a/libraries/src/Language/Associations.php b/libraries/src/Language/Associations.php index af0441f228e99..3a57e2aba19b4 100644 --- a/libraries/src/Language/Associations.php +++ b/libraries/src/Language/Associations.php @@ -43,7 +43,7 @@ public static function getAssociations($extension, $tablename, $context, $id, $p $advClause = array() ) { - $globalMasterLang = self::getGlobalMasterLanguage(); + $defaultAssocLang = self::getDefaultAssocLang(); // To avoid doing duplicate database queries. static $multilanguageAssociations = array(); @@ -128,9 +128,9 @@ public static function getAssociations($extension, $tablename, $context, $id, $p { foreach ($items as $tag => $item) { - if ($globalMasterLang) + if ($defaultAssocLang) { - // If a global master language is set, we need all items of an associations + // If a default association language is set, we need all items of an associations $multilanguageAssociations[$queryKey][$tag] = $item; } else @@ -185,19 +185,19 @@ public static function isEnabled() } /** - * Method to get the global master language parameter for associations. + * Method to get the default association language parameter for associations. * * @return string empty if not set, lang_code otherwise. * * @since 4.0 */ - public static function getGlobalMasterLanguage() + public static function getDefaultAssocLang() { // Flag to avoid doing multiple database queries. static $tested = false; - // Status of global master language parameter. - static $globalMasterLang = ''; + // Status of default association language parameter. + static $defaultAssocLang = ''; if (self::isEnabled()) { @@ -209,13 +209,13 @@ public static function getGlobalMasterLanguage() if (!empty($plugin)) { $params = new Registry($plugin->params); - $globalMasterLang = $params->get('global_master_language'); + $defaultAssocLang = $params->get('default_assoc_lang'); } $tested = true; } } - return $globalMasterLang ?? ''; + return $defaultAssocLang ?? ''; } } diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 09965558c450d..ffc6d78e0d239 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -23,7 +23,7 @@ use Joomla\CMS\Router\Route; use Joomla\CMS\Table\Table; use Joomla\CMS\UCM\UCMType; -use Joomla\Component\Associations\Administrator\Helper\MasterAssociationsHelper; +use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; use Joomla\Registry\Registry; use Joomla\String\StringHelper; use Joomla\Utilities\ArrayHelper; @@ -1323,7 +1323,7 @@ public function save($data) // Get association params before they get deleted if ($associations) { - $assocMasterDates = MasterAssociationsHelper::getMasterDates($associations, $this->associationsContext); + $assocParentDates = DefaultAssocLangHelper::getParentDates($associations, $this->associationsContext); } // Get associationskey for edited item @@ -1363,15 +1363,15 @@ public function save($data) if (count($associations) > 1) { - // If there is an association item with the globalMasterLanguage, then get its id - $globalMasterLang = Associations::getGlobalMasterLanguage(); - $masterId = $associations[$globalMasterLang] ?? ''; + // If there is an associated item with the default association language, then get its id + $defaultAssocLang = Associations::getDefaultAssocLang(); + $parentId = $associations[$defaultAssocLang] ?? ''; // Get id of the item that get saved $dataId = (int) $table->id; - // Get the latest modified date of master item - $masterModified = MasterAssociationsHelper::getMasterModifiedDate($masterId, $table->getTableName(), $table->typeAlias); + // Get the latest modified date of the parent + $parentModified = DefaultAssocLangHelper::getParentModifiedDate($parentId, $table->getTableName(), $table->typeAlias); // Adding new association for these items $key = md5(json_encode($associations) . $context); @@ -1379,13 +1379,13 @@ public function save($data) foreach ($associations as $id) { - $masterIdAndDateValues = MasterAssociationsHelper::getMasterValues($id, $dataId, $masterId, $masterModified, $assocMasterDates, $old_key); - $masterIdValue = $masterIdAndDateValues[0]; - $masterDateValue = $masterIdAndDateValues[1] === 'NULL' ? $masterIdAndDateValues[1] : $db->quote($masterIdAndDateValues[1]); + $parentIdAndDateValues = DefaultAssocLangHelper::getParentValues($id, $dataId, $parentId, $parentModified, $assocParentDates, $old_key); + $parentIdValue = $parentIdAndDateValues[0]; + $parentDateValue = $parentIdAndDateValues[1] === 'NULL' ? $parentIdAndDateValues[1] : $db->quote($parentIdAndDateValues[1]); $query->values( ((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) - . ',' . $db->quote($masterIdValue) . ',' . $masterDateValue + . ',' . $db->quote($parentIdValue) . ',' . $parentDateValue ); } @@ -1670,16 +1670,16 @@ public function editAssociations($data) } } - $globalMasterLang = Associations::getGlobalMasterLanguage(); - $isMaster = $data['language'] === $globalMasterLang; + $defaultAssocLang = Associations::getDefaultAssocLang(); + $isParent = $data['language'] === $defaultAssocLang; - // If a global Master Language is set and the current item is a child item, then open the master item as reference and the child as target - if ($globalMasterLang && !$isMaster) + // If a default association language is set and the current item is a child item, then open his parent as reference and the child as target + if ($defaultAssocLang && !$isParent) { - // If there is an associated master item change reference id. - if ($data['associations'][$globalMasterLang]) + // If there is an associated parent, change reference id. + if ($data['associations'][$defaultAssocLang]) { - $id = $data['associations'][$globalMasterLang]; + $id = $data['associations'][$defaultAssocLang]; $target = '&target=' . $data['language'] . '%3A' . $data['id'] . '%3Aedit'; } } diff --git a/plugins/sampledata/multilang/multilang.php b/plugins/sampledata/multilang/multilang.php index a7a9ae05c7eed..85605a67db93d 100644 --- a/plugins/sampledata/multilang/multilang.php +++ b/plugins/sampledata/multilang/multilang.php @@ -518,8 +518,8 @@ private function enablePlugin($pluginName) . '"remove_default_prefix":"0",' . '"lang_cookie":"0",' . '"alternate_meta":"1",' - . '"use_master_language":0,' - . '"global_master_language":""' + . '"use_default_assoc_lang":0,' + . '"default_assoc_lang":""' . '}'; $query ->clear() diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index acf261c28fdf9..db9e5acac1df4 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -964,12 +964,12 @@ private function getLanguageCookie() return $languageCode; } - // Events for Masterlanguage: + // Events for Default Association Language: /** * Before Saving extensions * Method is called when an extension is going to be saved. - * Change parameters for master language as they depends on other parameters. + * Change parameters for default association language as they depends on other parameters. * * @param string $context The extension * @param JTable $table DataBase Table object @@ -991,22 +991,22 @@ public function onExtensionBeforeSave($context, $table) return true; } - // If the plugin and the parameter item_associations are enabled then set the correct value for the global master language. + // If the plugin and the parameter item_associations are enabled then set the correct value for the default association language. if ($pluginStatus && $itemAssocStatus) { - $params->global_master_language = ($params->use_master_language === 1) - ? $params->global_master_language + $params->default_assoc_lang = ($params->use_default_assoc_lang === 1) + ? $params->default_assoc_lang : ''; } - // Reset parameters for master language + // Reset parameters for default association language else { - $params->use_master_language = ''; - $params->global_master_language = ''; + $params->use_default_assoc_lang = ''; + $params->default_assoc_lang = ''; } - // Check if there were changes for the master language - $this->hasMasterLangChanged = ($params->global_master_language === $this->params->get('global_master_language')) ? false : true; + // Check if there were changes for the default association language. + $this->hasAssocLangChanged = ($params->default_assoc_lang === $this->params->get('default_assoc_lang')) ? false : true; return $table->params = json_encode($params); } @@ -1033,21 +1033,21 @@ public function onExtensionAfterSave($context, $table) return true; } - // Only set master items if the global master language has changed. - if ($this->hasMasterLangChanged) + // Only set association parent items if the default association language has changed. + if ($this->hasAssocLangChanged) { - $this->_setMasterItem($params->global_master_language); + $this->_setParentItem($params->default_assoc_lang); } - unset($this->hasMasterLangChanged); + unset($this->hasAssocLangChanged); } /** - * Method to set the master id and modified dates to all associated items. - * This resets all current master ids and modified dates and set these new. - * Master and children will be up-to-date, as they get the same modified date. + * Method to set the parent id and modified dates to all associated items. + * This resets all current parent ids and modified dates and set these new. + * Parent and children will be up-to-date, as they get the same modified date. * - * @param string $language The global master language + * @param string $language The default association language * * @return boolean Returns true on success, false on failure. * @@ -1055,18 +1055,18 @@ public function onExtensionAfterSave($context, $table) * * @since 4.0.0 */ - private function _setMasterItem($language) + private function _setParentItem($language) { - $db = Factory::getDbo(); - $masterLanguage = $language; + $db = Factory::getDbo(); + $defaultAssocLang = $language; - // If there is no global masterlanguage set, set all master ids to -1 and master dates to null - if (!$masterLanguage) + // If there is no default association language set, set all parent ids to -1 and parent dates to null + if (!$defaultAssocLang) { $resetQuery = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('master_id') . ' = -1') - ->set($db->quoteName('master_date') . ' = NULL'); + ->set($db->quoteName('parent_id') . ' = -1') + ->set($db->quoteName('parent_date') . ' = NULL'); $db->setQuery($resetQuery); try @@ -1119,21 +1119,21 @@ private function _setMasterItem($language) $modified = ($component === 'com_menus') ? '' : $db->quoteName('e.modified'); } - // Get ids of items with the global master language + // Get ids of items with the default association language $subQuery = $db->getQuery(true) ->select($db->quoteName('e.id')) ->from($fromTable) - ->where($db->quoteName('e.language') . ' = ' . $db->quote($masterLanguage)); + ->where($db->quoteName('e.language') . ' = ' . $db->quote($defaultAssocLang)); - // Get master id of an item that has the global master language - $masterQuery = $db->getQuery(true) + // Get parent id of an item that has the default association language + $parentQuery = $db->getQuery(true) ->select($db->quoteName('id')) ->from('#__associations') ->where($db->quoteName('id') . ' IN (' . $subQuery . ')') ->where($db->quoteName('key') . ' = ' . $db->quote($value)); - $masterId = $db->setQuery($masterQuery)->loadResult(); + $parentId = $db->setQuery($parentQuery)->loadResult(); - // Get masters modified date + // Get modified date of parent if ($modified) { // Get the context of this category @@ -1142,42 +1142,42 @@ private function _setMasterItem($language) $categoryQuery = $db->getQuery(true) ->select($checkCategoryComponent) ->from($fromTable) - ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); - $categoryMasterExtension = $db->setQuery($categoryQuery)->loadResult(); - $typeAlias = $categoryMasterExtension . '.category'; + ->where($db->quoteName('id') . ' = ' . $db->quote($parentId)); + $categoryParentExtension = $db->setQuery($categoryQuery)->loadResult(); + $typeAlias = $categoryParentExtension . '.category'; } - $component = $categoryMasterExtension ?? $component; + $component = $categoryParentExtension ?? $component; $saveHistory = ComponentHelper::getParams($component)->get('save_history', 0); - // If versions are enabled get the save_date of the master item from history table otherwise use the modified date + // If versions are enabled get the save_date of the parent item from history table otherwise use the modified date if ($saveHistory) { $typeId = Table::getInstance('ContentType')->getTypeId($typeAlias); - $masterHistory = ContentHistoryHelper::getHistory($typeId, $masterId); + $parentHistory = ContentHistoryHelper::getHistory($typeId, $parentId); - // Latest saved date of the master item - $masterModified = $masterHistory[0]->save_date; + // Latest saved date of the parent item + $parentModified = $parentHistory[0]->save_date; } else { - $masterModQuery = $db->getQuery(true) + $parentModQuery = $db->getQuery(true) ->select($modified) ->from($fromTable) - ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)); - $masterModified = $db->setQuery($masterModQuery)->loadResult(); + ->where($db->quoteName('id') . ' = ' . $db->quote($parentId)); + $parentModified = $db->setQuery($parentModQuery)->loadResult(); } } - $masterModified = $modified ? $db->quote($masterModified) : 'NULL'; - $masterId = $masterId ?? -1; + $parentModified = $modified ? $db->quote($parentModified) : 'NULL'; + $parentId = $parentId ?? -1; - // Set the id and the modified date of the master item. + // Set the id and the modified date of the parent item. $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('master_id') . ' = ' . $db->quote(0)) - ->set($db->quoteName('master_date') . ' = ' . $masterModified) - ->where($db->quoteName('id') . ' = ' . $db->quote($masterId)) + ->set($db->quoteName('parent_id') . ' = ' . $db->quote(0)) + ->set($db->quoteName('parent_date') . ' = ' . $parentModified) + ->where($db->quoteName('id') . ' = ' . $db->quote($parentId)) ->where($db->quoteName('key') . ' = ' . $db->quote($value)) ->where($db->quoteName('context') . ' = ' . $db->quote($assocContext)); $db->setQuery($query); @@ -1191,12 +1191,12 @@ private function _setMasterItem($language) return false; } - // Set the id and modified date of the master item to the children + // Set the id and modified date of the parent item to the children $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('master_id') . ' = ' . $db->quote($masterId)) - ->set($db->quoteName('master_date') . ' = ' . $masterModified) - ->where($db->quoteName('id') . ' <> ' . $db->quote($masterId)) + ->set($db->quoteName('parent_id') . ' = ' . $db->quote($parentId)) + ->set($db->quoteName('parent_date') . ' = ' . $parentModified) + ->where($db->quoteName('id') . ' <> ' . $db->quote($parentId)) ->where($db->quoteName('key') . ' = ' . $db->quote($value)) ->where($db->quoteName('context') . ' = ' . $db->quote($assocContext)); $db->setQuery($query); diff --git a/plugins/system/languagefilter/languagefilter.xml b/plugins/system/languagefilter/languagefilter.xml index ae0708707ad88..c7aff4fbac573 100644 --- a/plugins/system/languagefilter/languagefilter.xml +++ b/plugins/system/languagefilter/languagefilter.xml @@ -62,10 +62,10 @@ From 9f5c7a3124794f89a1bf8d31ae4be6da1375582c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Wed, 21 Aug 2019 13:50:21 +0200 Subject: [PATCH 83/98] use prepared statements and save parent_date value as date The value for parent_date was saved as string, now the method "Factory::getDate()->toSql()" is used to save the value as date. --- .../Helper/DefaultAssocLangHelper.php | 22 ++++-- .../Model/AssociationModel.php | 42 ++++++++--- .../Model/AssociationsModel.php | 20 +++--- .../Model/DefaultAssocLangModel.php | 25 +++++-- .../com_categories/Model/CategoryModel.php | 51 ++++++++----- .../Service/HTML/AdministratorService.php | 17 +++-- .../Service/HTML/AdministratorService.php | 19 +++-- .../Service/HTML/AdministratorService.php | 19 +++-- .../components/com_menus/Model/ItemModel.php | 34 ++++----- .../com_menus/Service/HTML/Menus.php | 19 +++-- .../Service/HTML/AdministratorService.php | 19 +++-- installation/src/Model/LanguagesModel.php | 32 +++++---- libraries/src/MVC/Model/AdminModel.php | 34 ++++++--- plugins/sampledata/multilang/multilang.php | 36 ++++++---- .../system/languagefilter/languagefilter.php | 72 ++++++++++++++----- 15 files changed, 288 insertions(+), 173 deletions(-) diff --git a/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php b/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php index c0076c2b5fa58..e573882a47cfd 100644 --- a/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php +++ b/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php @@ -16,6 +16,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; use Joomla\CMS\Table\Table; +use Joomla\Database\ParameterType; defined('_JEXEC') or die; @@ -39,9 +40,10 @@ public static function addNotAssociatedParentLink($defaultAssocLang, $itemId, $i { $db = Factory::getDbo(); $query = $db->getQuery(true) - ->select('title, sef') - ->from('#__languages') - ->where($db->quoteName('lang_code') . ' = ' . $db->quote($defaultAssocLang)); + ->select($db->quoteName(['title', 'sef'])) + ->from($db->quoteName('#__languages')) + ->where($db->quoteName('lang_code') . ' = :lang_code') + ->bind(':lang_code', $defaultAssocLang); $db->setQuery($query); $defaultAssocLangInfos = $db->loadAssoc(); @@ -82,8 +84,12 @@ public static function getParentDates($associations, $context) $query = $db->getQuery(true) ->select($db->quoteName('parent_date')) ->from($db->quoteName('#__associations')) - ->where($db->quoteName('id') . ' = ' . $db->quote($id)) - ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + ->where([ + $db->quoteName('id') . ' = :id', + $db->quoteName('context') . ' = :context' + ]) + ->bind(':id', $id, ParameterType::INTEGER) + ->bind(':context', $context); $db->setQuery($query); $parentDates[$id] = $db->loadResult(); } @@ -165,7 +171,8 @@ public static function getParentModifiedDate($parentId, $tableName, $typeAlias) $fieldMapsQuery = $db->getQuery(true) ->select($db->quoteName('field_mappings')) ->from($db->quoteName($contentTypeTblName)) - ->where($db->quoteName('type_id') . ' = ' . $db->quote($typeId)); + ->where($db->quoteName('type_id') . ' = :type_id') + ->bind(':type_id', $typeId, ParameterType::INTEGER); $db->setQuery($fieldMapsQuery); $fieldMaps = $db->loadResult(); @@ -186,7 +193,8 @@ public static function getParentModifiedDate($parentId, $tableName, $typeAlias) $parentDateQuery = $db->getQuery(true) ->select($db->quoteName($modifiedColumn)) ->from($db->quoteName($tableName)) - ->where($db->quoteName('id') . ' = ' . $db->quote($parentId)); + ->where($db->quoteName('id') . ' = :id') + ->bind(':id', $parentId, ParameterType::INTEGER); $db->setQuery($parentDateQuery); $parentModified = $db->loadResult(); } diff --git a/administrator/components/com_associations/Model/AssociationModel.php b/administrator/components/com_associations/Model/AssociationModel.php index bf7ddeb8dde23..e11e6ab941215 100644 --- a/administrator/components/com_associations/Model/AssociationModel.php +++ b/administrator/components/com_associations/Model/AssociationModel.php @@ -13,6 +13,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\MVC\Model\ListModel; +use Joomla\Database\ParameterType; /** * Methods supporting a list of article records. @@ -61,32 +62,51 @@ public function getParentCompareValues($parentId, $targetId, $extensionName, $ty $parentQuery = $db->getQuery(true) ->select($db->quoteName('parent_date')) ->from($db->quoteName('#__associations')) - ->where($db->quoteName('id') . ' = ' . $db->quote($parentId)) - ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + ->where([ + $db->quoteName('id') . ' = :id', + $db->quoteName('context') . ' = :context' + ]) + ->bind(':id', $parentId, ParameterType::INTEGER) + ->bind(':context', $context); $latestParentDate = $db->setQuery($parentQuery)->loadResult(); $latestVersionQuery = $db->getQuery(true) ->select($db->quoteName('version_id')) ->from($db->quoteName('#__ucm_history')) - ->where($db->quoteName('ucm_item_id') . ' = ' . $db->quote($parentId)) - ->where($db->quoteName('ucm_type_id') . ' = ' . $db->quote($typeId)) - ->where($db->quoteName('save_date') . ' = ' . $db->quote($latestParentDate)); + ->where([ + $db->quoteName('ucm_item_id') . ' = :ucm_item_id', + $db->quoteName('ucm_type_id') . ' = :ucm_type_id', + $db->quoteName('save_date') . ' = :save_date' + ]) + ->bind(':ucm_item_id', $parentId, ParameterType::INTEGER) + ->bind(':ucm_type_id', $typeId, ParameterType::INTEGER) + ->bind(':save_date', $latestParentDate); $latestVersionId = $db->setQuery($latestVersionQuery)->loadResult(); $childQuery = $db->getQuery(true) ->select($db->quoteName('parent_date')) ->from($db->quoteName('#__associations')) - ->where($db->quoteName('id') . ' = ' . $db->quote($targetId)) - ->where($db->quoteName('parent_id') . ' = ' . $db->quote($parentId)) - ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + ->where([ + $db->quoteName('id') . ' = :id', + $db->quoteName('parent_id') . ' = :parent_id', + $db->quoteName('context') . ' = :context' + ]) + ->bind(':id', $targetId, ParameterType::INTEGER) + ->bind(':parent_id', $parentId, ParameterType::INTEGER) + ->bind(':context', $context); $childParentDate = $db->setQuery($childQuery)->loadResult(); $olderVersionQuery = $db->getQuery(true) ->select($db->quoteName('version_id')) ->from($db->quoteName('#__ucm_history')) - ->where($db->quoteName('ucm_item_id') . ' = ' . $db->quote($parentId)) - ->where($db->quoteName('ucm_type_id') . ' = ' . $db->quote($typeId)) - ->where($db->quoteName('save_date') . ' = ' . $db->quote($childParentDate)); + ->where([ + $db->quoteName('ucm_item_id') . ' = :ucm_item_id', + $db->quoteName('ucm_type_id') . ' = :ucm_type_id', + $db->quoteName('save_date') . ' = :save_date' + ]) + ->bind(':ucm_item_id', $parentId, ParameterType::INTEGER) + ->bind(':ucm_type_id', $typeId, ParameterType::INTEGER) + ->bind(':save_date', $childParentDate); $olderVersionId = $db->setQuery($olderVersionQuery)->loadResult(); return [$latestVersionId, $olderVersionId]; diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index b82c825980aad..2c7cc7202896c 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -20,6 +20,7 @@ use Joomla\CMS\Table\Table; use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper; use Joomla\Database\Exception\ExecutionFailureException; +use Joomla\Database\ParameterType; /** * Methods supporting a list of article records. @@ -247,12 +248,12 @@ protected function getListQuery() // Join over the associations. $query->select('COUNT(' . $db->quoteName('asso2.id') . ') > 1 AS ' . $db->quoteName('association')) - ->join( - 'LEFT', + ->leftJoin ( $db->quoteName('#__associations', 'asso') . ' ON ' . $db->quoteName('asso.id') . ' = ' . $db->quoteName($fields['id']) - . ' AND ' . $db->quoteName('asso.context') . ' = ' . $db->quote($assocContextName) + . ' AND ' . $db->quoteName('asso.context') . ' = :context' ) - ->join('LEFT', $db->quoteName('#__associations', 'asso2') . ' ON ' . $db->quoteName('asso2.key') . ' = ' . $db->quoteName('asso.key')); + ->leftJoin($db->quoteName('#__associations', 'asso2') . ' ON ' . $db->quoteName('asso2.key') . ' = ' . $db->quoteName('asso.key')) + ->bind(':context', $assocContextName); // Prepare the group by clause. $groupby = array( @@ -452,7 +453,7 @@ protected function getListQuery() // Not associated if ($assocStateField === 'not_associated') { - $languageQuery = $db->getQuery(true) + $languageQuery = $db->getQuery(true) ->select('COUNT(*)') ->from($db->quoteName('#__languages')); $db->setQuery($languageQuery); @@ -542,11 +543,14 @@ public function purge($context = '', $key = '') $subQuery = $db->getQuery(true) ->select($db->quoteName('id')) ->from($db->quoteName('#__categories')) - ->where($db->quoteName('extension') . ' = ' . $db->quote($extensionName)); + ->where($db->quoteName('extension') . ' = :extension') + ->bind(':extension', $extensionName); + $idResults = $db->setQuery($subQuery)->loadColumn(); // Delete associations of categories with the given context by comparing id of both tables - $query->where($db->quoteName('id') . ' IN (' . $subQuery . ')') - ->where($db->quoteName('context') . ' = ' . $db->quote('com_categories.item')); + $query->whereIn($db->quoteName('id'), $idResults, ParameterType::INTEGER) + ->where($db->quoteName('context') . ' = :context') + ->bind(':context', $context = 'com_categories.item'); } else { diff --git a/administrator/components/com_associations/Model/DefaultAssocLangModel.php b/administrator/components/com_associations/Model/DefaultAssocLangModel.php index bafcd94f3bfae..805e014458062 100644 --- a/administrator/components/com_associations/Model/DefaultAssocLangModel.php +++ b/administrator/components/com_associations/Model/DefaultAssocLangModel.php @@ -13,6 +13,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\MVC\Model\BaseModel; +use Joomla\Database\ParameterType; /** * Methods supporting a list of article records. @@ -45,17 +46,27 @@ public function update($childId, $parentId, $itemtype) $subQuery = $db->getQuery(true) ->select($db->quoteName('parent_date')) ->from($db->quoteName('#__associations')) - ->where($db->quoteName('id') . ' = ' . $db->quote($parentId)) - ->where($db->quoteName('parent_id') . ' = ' . $db->quote(0)) - ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + ->where([ + $db->quoteName('id') . ' = :id', + $db->quoteName('parent_id') . ' = ' . $db->quote(0), + $db->quoteName('context') . ' = :context' + ]) + ->bind(':id', $parentId, ParameterType::INTEGER) + ->bind(':context', $context); $parentModified = $db->setQuery($subQuery)->loadResult(); $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('parent_date') . ' = ' . $db->quote($parentModified)) - ->where($db->quoteName('id') . ' = ' . $db->quote($childId)) - ->where($db->quoteName('parent_id') . ' = ' . $db->quote($parentId)) - ->where($db->quoteName('context') . ' = ' . $db->quote($context)); + ->set($db->quoteName('parent_date') . ' = :parent_date') + ->where([ + $db->quoteName('id') . ' = :id', + $db->quoteName('parent_id') . ' = :parent_id', + $db->quoteName('context') . ' = :context' + ]) + ->bind(':parent_date', $parentModified = Factory::getDate($parentModified)->toSql()) + ->bind(':id', $childId, ParameterType::INTEGER) + ->bind(':parent_id', $parentId, ParameterType::INTEGER) + ->bind(':context', $context); $db->setQuery($query); try diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index 96291125407d5..0dd869f7a36d8 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -29,6 +29,7 @@ use Joomla\CMS\UCM\UCMType; use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; +use Joomla\Database\ParameterType; use Joomla\Registry\Registry; use Joomla\String\StringHelper; use Joomla\Utilities\ArrayHelper; @@ -683,7 +684,7 @@ public function save($data) { // If there is an association item with the default association language, then get its id $defaultAssocLang = Associations::getDefaultAssocLang(); - $parentId = $associations[$defaultAssocLang] ?? ''; + $parentId = $associations[$defaultAssocLang] ?? ''; // Id of the saved item $dataId = (int) $table->id; @@ -693,32 +694,44 @@ public function save($data) // Adding new association for these items $key = md5(json_encode($associations)); - $query->clear() - ->insert('#__associations'); foreach ($associations as $id) { - $parentIdAndDateValues = DefaultAssocLangHelper::getParentValues($id, $dataId, $parentId, $parentModified, $assocParentDates, $oldKey); + $parentIdAndDateValues = DefaultAssocLangHelper::getParentValues($id, $dataId, $parentId, $parentModified, $assocParentDates, + $oldKey); $parentIdValue = $parentIdAndDateValues[0]; - $parentDateValue = $parentIdAndDateValues[1] === 'NULL' ? $parentIdAndDateValues[1] : $db->quote($parentIdAndDateValues[1]); + $parentDateValue = $parentIdAndDateValues[1] === 'NULL' ? 'NULL' : Factory::getDate($parentIdAndDateValues[1])->toSql(); - $query->values( - ((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) . ',' - . $db->quote($parentIdValue) . ',' . $parentDateValue - ); - } + $query->clear() + ->insert($db->quoteName('#__associations')); - $db->setQuery($query); + if ($parentDateValue === 'NULL') + { + $query->values((' :id, :context, :key, :parentId, NULL')); + } + else + { + $query->values((' :id, :context, :key, :parentId, :parentDate')) + ->bind(':parentDate', $parentDateValue); + } - try - { - $db->execute(); - } - catch (\RuntimeException $e) - { - $this->setError($e->getMessage()); + $query->bind(':id', $id, ParameterType::INTEGER) + ->bind(':context', $this->associationsContext) + ->bind(':key', $key) + ->bind(':parentId', $parentIdValue, ParameterType::INTEGER); - return false; + $db->setQuery($query); + + try + { + $db->execute(); + } + catch (\RuntimeException $e) + { + $this->setError($e->getMessage()); + + return false; + } } } } diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index 2b45788c46b16..d6f8c3e5259eb 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -18,6 +18,7 @@ use Joomla\CMS\Router\Route; use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; +use Joomla\Database\ParameterType; use Joomla\Utilities\ArrayHelper; /** @@ -55,21 +56,19 @@ public function association($catid, $extension = 'com_content') // Get the associated categories $db = Factory::getDbo(); $query = $db->getQuery(true) - ->select('c.id, c.title') - ->select('l.sef as lang_sef') - ->select('l.lang_code') - ->from('#__categories as c') - ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); + ->select($db->quoteName(['c.id', 'c.title', 'l.lang_code', 'l.image'])) + ->select($db->quoteName(['l.sef', 'l.title'], ['lang_sef', 'language_title'])) + ->from($db->quoteName('#__categories', 'c')) + ->whereIN($db->quoteName('c.id'), array_values($associations)); // Don't get the id of the item itself when there is no default association language used. if (!$defaultAssocLang) { - $query->where('c.id != ' . $catid); + $query->where($db->quoteName('c.id') . ' != :id') + ->bind(':id', $catid, ParameterType::INTEGER); } - $query->join('LEFT', '#__languages as l ON c.language=l.lang_code') - ->select('l.image') - ->select('l.title as language_title'); + $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')); $db->setQuery($query); try diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index aa0ce75417c11..bff7cde812154 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -18,6 +18,7 @@ use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; +use Joomla\Database\ParameterType; use Joomla\Utilities\ArrayHelper; /** @@ -56,22 +57,20 @@ public function association($contactid) // Get the associated contact items $db = Factory::getDbo(); $query = $db->getQuery(true) - ->select('c.id, c.name as title') - ->select('l.sef as lang_sef, lang_code') - ->from('#__contact_details as c') - ->select('cat.title as category_title') - ->join('LEFT', '#__categories as cat ON cat.id=c.catid') - ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); + ->select($db->quoteName(['c.id', 'lang_code', 'l.image'])) + ->select($db->quoteName(['c.name', 'l.sef', 'cat.title', 'l.title'], ['title', 'lang_sef', 'category_title', 'language_title'])) + ->from($db->quoteName('#__contact_details', 'c')) + ->leftJoin($db->quoteName('#__categories', 'cat'), $db->quoteName('cat.id') . ' = ' . $db->quoteName('c.catid')) + ->whereIN($db->quoteName('c.id'), array_values($associations)); // Don't get the id of the item itself when there is no default association language used. if (!$defaultAssocLang) { - $query->where('c.id != ' . $contactid); + $query->where($db->quoteName('c.id') . ' != :id') + ->bind(':id', $contactid, ParameterType::INTEGER); } - $query->join('LEFT', '#__languages as l ON c.language=l.lang_code') - ->select('l.image') - ->select('l.title as language_title'); + $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')); $db->setQuery($query); try diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index 2f212eda9c6ca..b544aaae117ef 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -18,6 +18,7 @@ use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; +use Joomla\Database\ParameterType; use Joomla\Utilities\ArrayHelper; /** @@ -58,22 +59,20 @@ public function association($articleid) $db = Factory::getDbo(); $query = $db->getQuery(true) ->select('c.*') - ->select('l.sef as lang_sef') - ->select('l.lang_code') - ->from('#__content as c') - ->select('cat.title as category_title') - ->join('LEFT', '#__categories as cat ON cat.id=c.catid') - ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); + ->select($db->quoteName(['l.lang_code', 'l.image'])) + ->select($db->quoteName(['l.sef', 'cat.title', 'l.title'], ['lang_sef', 'category_title', 'language_title'])) + ->from($db->quoteName('#__content', 'c')) + ->leftJoin($db->quoteName('#__categories', 'cat'), $db->quoteName('cat.id') . ' = ' . $db->quoteName('c.catid')) + ->whereIN($db->quoteName('c.id'), array_values($associations)); // Don't get the id of the item itself when there is no default association language used. if (!$defaultAssocLang) { - $query->where('c.id != ' . $articleid); + $query->where($db->quoteName('c.id') . ' != :id') + ->bind(':id', $articleid, ParameterType::INTEGER); } - $query->join('LEFT', '#__languages as l ON c.language=l.lang_code') - ->select('l.image') - ->select('l.title as language_title'); + $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')); $db->setQuery($query); try diff --git a/administrator/components/com_menus/Model/ItemModel.php b/administrator/components/com_menus/Model/ItemModel.php index ba1bb2497e27b..a3f654a023b0b 100644 --- a/administrator/components/com_menus/Model/ItemModel.php +++ b/administrator/components/com_menus/Model/ItemModel.php @@ -23,6 +23,7 @@ use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Uri\Uri; use Joomla\Component\Menus\Administrator\Helper\MenusHelper; +use Joomla\Database\ParameterType; use Joomla\Registry\Registry; use Joomla\String\StringHelper; use Joomla\Utilities\ArrayHelper; @@ -1586,31 +1587,32 @@ public function save($data) // Adding new association for these items $key = md5(json_encode($associations)); - $query->clear() - ->insert('#__associations'); foreach ($associations as $id) { // If there is no parent in this association, then reset the parent id. // Otherwise, if the associated item is a parent, set its parent id to 0, otherwise to the parent Id. $parentIdValue = $parentId ? ($parentId === $id ? 0 : $parentId) : -1; - $query->values( - ((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) - . ',' . $db->quote($parentIdValue) . ', NULL' - ); - } + $query->clear() + ->insert($db->quoteName('#__associations')) + ->values((' :id, :context, :key, :parentId, NULL')) + ->bind(':id', $id, ParameterType::INTEGER) + ->bind(':context', $this->associationsContext) + ->bind(':key', $key) + ->bind(':parentId', $parentIdValue, ParameterType::INTEGER); - $db->setQuery($query); + $db->setQuery($query); - try - { - $db->execute(); - } - catch (\RuntimeException $e) - { - $this->setError($e->getMessage()); + try + { + $db->execute(); + } + catch (\RuntimeException $e) + { + $this->setError($e->getMessage()); - return false; + return false; + } } } } diff --git a/administrator/components/com_menus/Service/HTML/Menus.php b/administrator/components/com_menus/Service/HTML/Menus.php index 83cb9c2b21cd9..c040677cc1f97 100644 --- a/administrator/components/com_menus/Service/HTML/Menus.php +++ b/administrator/components/com_menus/Service/HTML/Menus.php @@ -18,6 +18,7 @@ use Joomla\CMS\Router\Route; use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; use Joomla\Component\Menus\Administrator\Helper\MenusHelper; +use Joomla\Database\ParameterType; use Joomla\Registry\Registry; /** @@ -52,22 +53,20 @@ public function association($itemid) // Get the associated menu items $db = Factory::getDbo(); $query = $db->getQuery(true) - ->select('m.id, m.title') - ->select('l.sef as lang_sef, l.lang_code') - ->select('mt.title as menu_title') - ->from('#__menu as m') - ->join('LEFT', '#__menu_types as mt ON mt.menutype=m.menutype') - ->where('m.id IN (' . implode(',', array_values($associations)) . ')'); + ->select($db->quoteName(['m.id', 'm.title', 'l.lang_code', 'l.image'])) + ->select($db->quoteName(['l.sef', 'mt.title', 'l.title'], ['lang_sef', 'menu_title', 'language_title'])) + ->from($db->quoteName('#__menu', 'm')) + ->leftJoin($db->quoteName('#__menu_types', 'mt'), $db->quoteName('mt.menutype') . ' = ' . $db->quoteName('m.menutype')) + ->whereIN($db->quoteName('m.id'), array_values($associations)); // Don't get the id of the item itself when there is no default association language used if (!$defaultAssocLang) { - $query->where('m.id != ' . $itemid); + $query->where($db->quoteName('m.id') . ' != :id') + ->bind(':id', $itemid, ParameterType::INTEGER); } - $query->join('LEFT', '#__languages as l ON m.language=l.lang_code') - ->select('l.image') - ->select('l.title as language_title'); + $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('m.language') . ' = ' . $db->quoteName('l.lang_code')); $db->setQuery($query); try diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index 686f5d3527109..6cb2f3d961409 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -18,6 +18,7 @@ use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; +use Joomla\Database\ParameterType; /** * Utility class for creating HTML Grids. @@ -55,22 +56,20 @@ public function association($newsfeedid) // Get the associated newsfeed items $db = Factory::getDbo(); $query = $db->getQuery(true) - ->select('c.id, c.name as title') - ->select('l.sef as lang_sef, lang_code') - ->from('#__newsfeeds as c') - ->select('cat.title as category_title') - ->join('LEFT', '#__categories as cat ON cat.id=c.catid') - ->where('c.id IN (' . implode(',', array_values($associations)) . ')'); + ->select($db->quoteName(['c.id', 'lang_code', 'l.image'])) + ->select($db->quoteName(['c.name', 'l.sef', 'cat.title', 'l.title'], ['title', 'lang_sef', 'category_title', 'language_title'])) + ->from($db->quoteName('#__newsfeeds', 'c')) + ->leftJoin($db->quoteName('#__categories', 'cat'), $db->quoteName('cat.id') . ' = ' . $db->quoteName('c.catid')) + ->whereIN($db->quoteName('c.id'), array_values($associations)); // Don't get the id of the item itself when there is no default association language used if (!$defaultAssocLang) { - $query->where('c.id != ' . $newsfeedid); + $query->where($db->quoteName('c.id') . ' != :id') + ->bind(':id', $newsfeedid, ParameterType::INTEGER); } - $query->join('LEFT', '#__languages as l ON c.language=l.lang_code') - ->select('l.image') - ->select('l.title as language_title'); + $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')); $db->setQuery($query); try diff --git a/installation/src/Model/LanguagesModel.php b/installation/src/Model/LanguagesModel.php index 61f80d89d18e5..01572f5cfe383 100644 --- a/installation/src/Model/LanguagesModel.php +++ b/installation/src/Model/LanguagesModel.php @@ -25,6 +25,7 @@ use Joomla\CMS\Updater\Update; use Joomla\CMS\Updater\Updater; use Joomla\Database\Exception\ExecutionFailureException; +use Joomla\Database\ParameterType; /** * Language Installer model for the Joomla Core Installer. @@ -1413,26 +1414,31 @@ public function addAssociations($groupedAssociations) // If there is an association item with the default association language, get its id. $parentId = $associations[$defaultAssocLang] ?? ''; $key = md5(json_encode($associations)); - $query = $db->getQuery(true) - ->insert('#__associations'); foreach ($associations as $language => $id) { // If there is no parent within this association, then reset the parent_id to -1 // Otherwise, if the associated item is a parent set the parent_id to 0, otherwise to the parentId. $parentIdValue = $parentId ? ($parentId === $id ? 0 : $parentId) : -1; - $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote($parentIdValue) . ', NULL'); - } - - $db->setQuery($query); - try - { - $db->execute(); - } - catch (\RuntimeException $e) - { - return false; + $query = $db->getQuery(true) + ->insert($db->quoteName('#__associations')) + ->values((' :id, :context, :key, :parentId, NULL')) + ->bind(':id', $id, ParameterType::INTEGER) + ->bind(':context', $context) + ->bind(':key', $key) + ->bind(':parentId', $parentIdValue, ParameterType::INTEGER); + + $db->setQuery($query); + + try + { + $db->execute(); + } + catch (\RuntimeException $e) + { + return false; + } } } diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index ffc6d78e0d239..249aa299d0b7a 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -24,6 +24,7 @@ use Joomla\CMS\Table\Table; use Joomla\CMS\UCM\UCMType; use Joomla\Component\Associations\Administrator\Helper\DefaultAssocLangHelper; +use Joomla\Database\ParameterType; use Joomla\Registry\Registry; use Joomla\String\StringHelper; use Joomla\Utilities\ArrayHelper; @@ -1375,22 +1376,35 @@ public function save($data) // Adding new association for these items $key = md5(json_encode($associations) . $context); - $query = $db->getQuery(true)->insert('#__associations'); foreach ($associations as $id) { - $parentIdAndDateValues = DefaultAssocLangHelper::getParentValues($id, $dataId, $parentId, $parentModified, $assocParentDates, $old_key); + $parentIdAndDateValues = DefaultAssocLangHelper::getParentValues($id, $dataId, $parentId, $parentModified, $assocParentDates, + $old_key); $parentIdValue = $parentIdAndDateValues[0]; - $parentDateValue = $parentIdAndDateValues[1] === 'NULL' ? $parentIdAndDateValues[1] : $db->quote($parentIdAndDateValues[1]); + $parentDateValue = $parentIdAndDateValues[1] === 'NULL' ? 'NULL' : Factory::getDate($parentIdAndDateValues[1])->toSql(); - $query->values( - ((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key) - . ',' . $db->quote($parentIdValue) . ',' . $parentDateValue - ); - } + $query = $db->getQuery(true) + ->insert($db->quoteName('#__associations')); + + // save NULL for parent_date + if($parentDateValue === 'NULL'){ + $query->values((' :id, :context, :key, :parentId, NULL')); + } + else + { + $query->values((' :id, :context, :key, :parentId, :parentDate')) + ->bind(':parentDate', $parentDateValue); + } - $db->setQuery($query); - $db->execute(); + $query->bind(':id', $id, ParameterType::INTEGER) + ->bind(':context', $this->associationsContext) + ->bind(':key', $key) + ->bind(':parentId', $parentIdValue, ParameterType::INTEGER); + + $db->setQuery($query); + $db->execute(); + } } } diff --git a/plugins/sampledata/multilang/multilang.php b/plugins/sampledata/multilang/multilang.php index 85605a67db93d..958520651ce40 100644 --- a/plugins/sampledata/multilang/multilang.php +++ b/plugins/sampledata/multilang/multilang.php @@ -20,6 +20,7 @@ use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Table\Table; use Joomla\Database\Exception\ExecutionFailureException; +use Joomla\Database\ParameterType; /** * Sampledata - Multilang Plugin @@ -903,24 +904,29 @@ private function addAssociations($groupedAssociations) foreach ($groupedAssociations as $context => $associations) { - $key = md5(json_encode($associations)); - $query = $db->getQuery(true) - ->insert('#__associations'); + $key = md5(json_encode($associations)); + $parentId = -1; foreach ($associations as $language => $id) { - $query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key) . ',' . $db->quote('-1') . ', NULL'); - } - - $db->setQuery($query); - - try - { - $db->execute(); - } - catch (\RuntimeException $e) - { - return false; + $query = $db->getQuery(true) + ->insert($db->quoteName('#__associations')) + ->values((' :id, :context, :key, :parentId, NULL')) + ->bind(':id', $id, ParameterType::INTEGER) + ->bind(':context', $context) + ->bind(':key', $key) + ->bind(':parentId', $parentId, ParameterType::INTEGER); + + $db->setQuery($query); + + try + { + $db->execute(); + } + catch (\RuntimeException $e) + { + return false; + } } } diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index db9e5acac1df4..297d88718233c 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -30,8 +30,10 @@ use Joomla\CMS\Uri\Uri; use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper; use Joomla\Component\Menus\Administrator\Helper\MenusHelper; +use Joomla\Database\ParameterType; use Joomla\Registry\Registry; use Joomla\String\StringHelper; +use Joomla\Utilities\ArrayHelper; /** * Joomla! Language Filter Plugin. @@ -1094,7 +1096,8 @@ private function _setParentItem($language) $contextQuery = $db->getQuery(true) ->select($db->quoteName('context')) ->from($db->quoteName('#__associations')) - ->where($db->quoteName('key') . ' = ' . $db->quote($value)); + ->where($db->quoteName('key') . ' = :key') + ->bind(':key', $value); $assocContext = $db->setQuery($contextQuery)->loadResult(); // Get the right table to search for modified date or save_date from history @@ -1123,14 +1126,17 @@ private function _setParentItem($language) $subQuery = $db->getQuery(true) ->select($db->quoteName('e.id')) ->from($fromTable) - ->where($db->quoteName('e.language') . ' = ' . $db->quote($defaultAssocLang)); + ->where($db->quoteName('e.language') . ' = :lang') + ->bind(':lang', $defaultAssocLang); + $idResults = $db->setQuery($subQuery)->loadColumn(); // Get parent id of an item that has the default association language $parentQuery = $db->getQuery(true) ->select($db->quoteName('id')) - ->from('#__associations') - ->where($db->quoteName('id') . ' IN (' . $subQuery . ')') - ->where($db->quoteName('key') . ' = ' . $db->quote($value)); + ->from($db->quoteName('#__associations')) + ->whereIn($db->quoteName('id'), $idResults, ParameterType::INTEGER) + ->where($db->quoteName('key') . ' = :key') + ->bind(':key', $value); $parentId = $db->setQuery($parentQuery)->loadResult(); // Get modified date of parent @@ -1142,7 +1148,8 @@ private function _setParentItem($language) $categoryQuery = $db->getQuery(true) ->select($checkCategoryComponent) ->from($fromTable) - ->where($db->quoteName('id') . ' = ' . $db->quote($parentId)); + ->where($db->quoteName('id') . ' = :id') + ->bind(':id', $parentId, ParameterType::INTEGER); $categoryParentExtension = $db->setQuery($categoryQuery)->loadResult(); $typeAlias = $categoryParentExtension . '.category'; } @@ -1164,22 +1171,36 @@ private function _setParentItem($language) $parentModQuery = $db->getQuery(true) ->select($modified) ->from($fromTable) - ->where($db->quoteName('id') . ' = ' . $db->quote($parentId)); + ->where($db->quoteName('id') . ' = :id') + ->bind(':id', $parentId, ParameterType::INTEGER); $parentModified = $db->setQuery($parentModQuery)->loadResult(); } } - $parentModified = $modified ? $db->quote($parentModified) : 'NULL'; $parentId = $parentId ?? -1; // Set the id and the modified date of the parent item. $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('parent_id') . ' = ' . $db->quote(0)) - ->set($db->quoteName('parent_date') . ' = ' . $parentModified) - ->where($db->quoteName('id') . ' = ' . $db->quote($parentId)) - ->where($db->quoteName('key') . ' = ' . $db->quote($value)) - ->where($db->quoteName('context') . ' = ' . $db->quote($assocContext)); + ->set($db->quoteName('parent_id') . ' = ' . $db->quote(0)); + + if($modified){ + $query->set($db->quoteName('parent_date') . ' = :parentDate') + ->bind(':parentDate', $parentModified = Factory::getDate($parentModified)->toSql()); + } + else + { + $query->set($db->quoteName('parent_date') . ' = NULL'); + } + + $query->where([ + $db->quoteName('id') . ' = :id', + $db->quoteName('key') . ' = :key', + $db->quoteName('context') . ' = :context' + ]) + ->bind(':id', $parentId, ParameterType::INTEGER) + ->bind(':key', $value) + ->bind(':context', $assocContext); $db->setQuery($query); try @@ -1194,11 +1215,26 @@ private function _setParentItem($language) // Set the id and modified date of the parent item to the children $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) - ->set($db->quoteName('parent_id') . ' = ' . $db->quote($parentId)) - ->set($db->quoteName('parent_date') . ' = ' . $parentModified) - ->where($db->quoteName('id') . ' <> ' . $db->quote($parentId)) - ->where($db->quoteName('key') . ' = ' . $db->quote($value)) - ->where($db->quoteName('context') . ' = ' . $db->quote($assocContext)); + ->set($db->quoteName('parent_id') . ' = :parentId'); + + if($modified){ + $query->set($db->quoteName('parent_date') . ' = :parentDate') + ->bind(':parentDate', $parentModified = Factory::getDate($parentModified)->toSql()); + } + else + { + $query->set($db->quoteName('parent_date') . ' = NULL'); + } + + $query->where([ + $db->quoteName('id') . ' <> :id', + $db->quoteName('key') . ' = :key', + $db->quoteName('context') . ' = :context' + ]) + ->bind(':parentId', $parentId, ParameterType::INTEGER) + ->bind(':id', $parentId, ParameterType::INTEGER) + ->bind(':key', $value) + ->bind(':context', $assocContext); $db->setQuery($query); try From 6e7498571728c0e97322811380b8d88d01bcb085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Wed, 21 Aug 2019 15:24:58 +0200 Subject: [PATCH 84/98] fix phpcs --- .../Helper/DefaultAssocLangHelper.php | 10 ++-- .../Model/AssociationModel.php | 46 +++++++++++-------- .../Model/AssociationsModel.php | 2 +- .../Model/DefaultAssocLangModel.php | 24 ++++++---- .../com_categories/Model/CategoryModel.php | 5 +- .../Service/HTML/AdministratorService.php | 2 +- .../Service/HTML/AdministratorService.php | 2 +- .../Service/HTML/AdministratorService.php | 2 +- .../com_menus/Service/HTML/Menus.php | 2 +- .../Service/HTML/AdministratorService.php | 2 +- libraries/src/MVC/Model/AdminModel.php | 10 ++-- .../system/languagefilter/languagefilter.php | 24 ++++++---- 12 files changed, 77 insertions(+), 54 deletions(-) diff --git a/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php b/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php index e573882a47cfd..41f2c76859633 100644 --- a/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php +++ b/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php @@ -84,10 +84,12 @@ public static function getParentDates($associations, $context) $query = $db->getQuery(true) ->select($db->quoteName('parent_date')) ->from($db->quoteName('#__associations')) - ->where([ - $db->quoteName('id') . ' = :id', - $db->quoteName('context') . ' = :context' - ]) + ->where( + [ + $db->quoteName('id') . ' = :id', + $db->quoteName('context') . ' = :context' + ] + ) ->bind(':id', $id, ParameterType::INTEGER) ->bind(':context', $context); $db->setQuery($query); diff --git a/administrator/components/com_associations/Model/AssociationModel.php b/administrator/components/com_associations/Model/AssociationModel.php index e11e6ab941215..881ed5b9cffe1 100644 --- a/administrator/components/com_associations/Model/AssociationModel.php +++ b/administrator/components/com_associations/Model/AssociationModel.php @@ -62,10 +62,12 @@ public function getParentCompareValues($parentId, $targetId, $extensionName, $ty $parentQuery = $db->getQuery(true) ->select($db->quoteName('parent_date')) ->from($db->quoteName('#__associations')) - ->where([ - $db->quoteName('id') . ' = :id', - $db->quoteName('context') . ' = :context' - ]) + ->where( + [ + $db->quoteName('id') . ' = :id', + $db->quoteName('context') . ' = :context' + ] + ) ->bind(':id', $parentId, ParameterType::INTEGER) ->bind(':context', $context); $latestParentDate = $db->setQuery($parentQuery)->loadResult(); @@ -73,11 +75,13 @@ public function getParentCompareValues($parentId, $targetId, $extensionName, $ty $latestVersionQuery = $db->getQuery(true) ->select($db->quoteName('version_id')) ->from($db->quoteName('#__ucm_history')) - ->where([ - $db->quoteName('ucm_item_id') . ' = :ucm_item_id', - $db->quoteName('ucm_type_id') . ' = :ucm_type_id', - $db->quoteName('save_date') . ' = :save_date' - ]) + ->where( + [ + $db->quoteName('ucm_item_id') . ' = :ucm_item_id', + $db->quoteName('ucm_type_id') . ' = :ucm_type_id', + $db->quoteName('save_date') . ' = :save_date' + ] + ) ->bind(':ucm_item_id', $parentId, ParameterType::INTEGER) ->bind(':ucm_type_id', $typeId, ParameterType::INTEGER) ->bind(':save_date', $latestParentDate); @@ -86,11 +90,13 @@ public function getParentCompareValues($parentId, $targetId, $extensionName, $ty $childQuery = $db->getQuery(true) ->select($db->quoteName('parent_date')) ->from($db->quoteName('#__associations')) - ->where([ - $db->quoteName('id') . ' = :id', - $db->quoteName('parent_id') . ' = :parent_id', - $db->quoteName('context') . ' = :context' - ]) + ->where( + [ + $db->quoteName('id') . ' = :id', + $db->quoteName('parent_id') . ' = :parent_id', + $db->quoteName('context') . ' = :context' + ] + ) ->bind(':id', $targetId, ParameterType::INTEGER) ->bind(':parent_id', $parentId, ParameterType::INTEGER) ->bind(':context', $context); @@ -99,11 +105,13 @@ public function getParentCompareValues($parentId, $targetId, $extensionName, $ty $olderVersionQuery = $db->getQuery(true) ->select($db->quoteName('version_id')) ->from($db->quoteName('#__ucm_history')) - ->where([ - $db->quoteName('ucm_item_id') . ' = :ucm_item_id', - $db->quoteName('ucm_type_id') . ' = :ucm_type_id', - $db->quoteName('save_date') . ' = :save_date' - ]) + ->where( + [ + $db->quoteName('ucm_item_id') . ' = :ucm_item_id', + $db->quoteName('ucm_type_id') . ' = :ucm_type_id', + $db->quoteName('save_date') . ' = :save_date' + ] + ) ->bind(':ucm_item_id', $parentId, ParameterType::INTEGER) ->bind(':ucm_type_id', $typeId, ParameterType::INTEGER) ->bind(':save_date', $childParentDate); diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 2c7cc7202896c..6e76d4e36ecf5 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -248,7 +248,7 @@ protected function getListQuery() // Join over the associations. $query->select('COUNT(' . $db->quoteName('asso2.id') . ') > 1 AS ' . $db->quoteName('association')) - ->leftJoin ( + ->leftJoin( $db->quoteName('#__associations', 'asso') . ' ON ' . $db->quoteName('asso.id') . ' = ' . $db->quoteName($fields['id']) . ' AND ' . $db->quoteName('asso.context') . ' = :context' ) diff --git a/administrator/components/com_associations/Model/DefaultAssocLangModel.php b/administrator/components/com_associations/Model/DefaultAssocLangModel.php index 805e014458062..44a757dc9df1f 100644 --- a/administrator/components/com_associations/Model/DefaultAssocLangModel.php +++ b/administrator/components/com_associations/Model/DefaultAssocLangModel.php @@ -46,11 +46,13 @@ public function update($childId, $parentId, $itemtype) $subQuery = $db->getQuery(true) ->select($db->quoteName('parent_date')) ->from($db->quoteName('#__associations')) - ->where([ - $db->quoteName('id') . ' = :id', - $db->quoteName('parent_id') . ' = ' . $db->quote(0), - $db->quoteName('context') . ' = :context' - ]) + ->where( + [ + $db->quoteName('id') . ' = :id', + $db->quoteName('parent_id') . ' = ' . $db->quote(0), + $db->quoteName('context') . ' = :context' + ] + ) ->bind(':id', $parentId, ParameterType::INTEGER) ->bind(':context', $context); $parentModified = $db->setQuery($subQuery)->loadResult(); @@ -58,11 +60,13 @@ public function update($childId, $parentId, $itemtype) $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) ->set($db->quoteName('parent_date') . ' = :parent_date') - ->where([ - $db->quoteName('id') . ' = :id', - $db->quoteName('parent_id') . ' = :parent_id', - $db->quoteName('context') . ' = :context' - ]) + ->where( + [ + $db->quoteName('id') . ' = :id', + $db->quoteName('parent_id') . ' = :parent_id', + $db->quoteName('context') . ' = :context' + ] + ) ->bind(':parent_date', $parentModified = Factory::getDate($parentModified)->toSql()) ->bind(':id', $childId, ParameterType::INTEGER) ->bind(':parent_id', $parentId, ParameterType::INTEGER) diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index d4104f1914af6..41c92ee075983 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -697,8 +697,9 @@ public function save($data) foreach ($associations as $id) { - $parentIdAndDateValues = DefaultAssocLangHelper::getParentValues($id, $dataId, $parentId, $parentModified, $assocParentDates, - $oldKey); + $parentIdAndDateValues = DefaultAssocLangHelper::getParentValues( + $id, $dataId, $parentId, $parentModified, $assocParentDates, $oldKey + ); $parentIdValue = $parentIdAndDateValues[0]; $parentDateValue = $parentIdAndDateValues[1] === 'NULL' ? 'NULL' : Factory::getDate($parentIdAndDateValues[1])->toSql(); diff --git a/administrator/components/com_categories/Service/HTML/AdministratorService.php b/administrator/components/com_categories/Service/HTML/AdministratorService.php index d6f8c3e5259eb..c3a2a2e60142e 100644 --- a/administrator/components/com_categories/Service/HTML/AdministratorService.php +++ b/administrator/components/com_categories/Service/HTML/AdministratorService.php @@ -68,7 +68,7 @@ public function association($catid, $extension = 'com_content') ->bind(':id', $catid, ParameterType::INTEGER); } - $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')); + $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')); $db->setQuery($query); try diff --git a/administrator/components/com_contact/Service/HTML/AdministratorService.php b/administrator/components/com_contact/Service/HTML/AdministratorService.php index bff7cde812154..b8cb94107b5f0 100644 --- a/administrator/components/com_contact/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/Service/HTML/AdministratorService.php @@ -70,7 +70,7 @@ public function association($contactid) ->bind(':id', $contactid, ParameterType::INTEGER); } - $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')); + $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')); $db->setQuery($query); try diff --git a/administrator/components/com_content/Service/HTML/AdministratorService.php b/administrator/components/com_content/Service/HTML/AdministratorService.php index b544aaae117ef..b0ed7a8328236 100644 --- a/administrator/components/com_content/Service/HTML/AdministratorService.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -72,7 +72,7 @@ public function association($articleid) ->bind(':id', $articleid, ParameterType::INTEGER); } - $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')); + $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')); $db->setQuery($query); try diff --git a/administrator/components/com_menus/Service/HTML/Menus.php b/administrator/components/com_menus/Service/HTML/Menus.php index c040677cc1f97..f119cffd3c11a 100644 --- a/administrator/components/com_menus/Service/HTML/Menus.php +++ b/administrator/components/com_menus/Service/HTML/Menus.php @@ -66,7 +66,7 @@ public function association($itemid) ->bind(':id', $itemid, ParameterType::INTEGER); } - $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('m.language') . ' = ' . $db->quoteName('l.lang_code')); + $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('m.language') . ' = ' . $db->quoteName('l.lang_code')); $db->setQuery($query); try diff --git a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php index 6cb2f3d961409..ab3dd0df6cfa7 100644 --- a/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php +++ b/administrator/components/com_newsfeeds/Service/HTML/AdministratorService.php @@ -69,7 +69,7 @@ public function association($newsfeedid) ->bind(':id', $newsfeedid, ParameterType::INTEGER); } - $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')); + $query->leftJoin($db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')); $db->setQuery($query); try diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 249aa299d0b7a..c33bc1d362c85 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -1379,16 +1379,18 @@ public function save($data) foreach ($associations as $id) { - $parentIdAndDateValues = DefaultAssocLangHelper::getParentValues($id, $dataId, $parentId, $parentModified, $assocParentDates, - $old_key); + $parentIdAndDateValues = DefaultAssocLangHelper::getParentValues( + $id, $dataId, $parentId, $parentModified, $assocParentDates, $old_key + ); $parentIdValue = $parentIdAndDateValues[0]; $parentDateValue = $parentIdAndDateValues[1] === 'NULL' ? 'NULL' : Factory::getDate($parentIdAndDateValues[1])->toSql(); $query = $db->getQuery(true) ->insert($db->quoteName('#__associations')); - // save NULL for parent_date - if($parentDateValue === 'NULL'){ + // Save NULL for parent_date + if ($parentDateValue === 'NULL') + { $query->values((' :id, :context, :key, :parentId, NULL')); } else diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index 297d88718233c..c82330598250b 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -1184,7 +1184,8 @@ private function _setParentItem($language) ->update($db->quoteName('#__associations')) ->set($db->quoteName('parent_id') . ' = ' . $db->quote(0)); - if($modified){ + if ($modified) + { $query->set($db->quoteName('parent_date') . ' = :parentDate') ->bind(':parentDate', $parentModified = Factory::getDate($parentModified)->toSql()); } @@ -1193,11 +1194,13 @@ private function _setParentItem($language) $query->set($db->quoteName('parent_date') . ' = NULL'); } - $query->where([ + $query->where( + [ $db->quoteName('id') . ' = :id', $db->quoteName('key') . ' = :key', $db->quoteName('context') . ' = :context' - ]) + ] + ) ->bind(':id', $parentId, ParameterType::INTEGER) ->bind(':key', $value) ->bind(':context', $assocContext); @@ -1217,7 +1220,8 @@ private function _setParentItem($language) ->update($db->quoteName('#__associations')) ->set($db->quoteName('parent_id') . ' = :parentId'); - if($modified){ + if ($modified) + { $query->set($db->quoteName('parent_date') . ' = :parentDate') ->bind(':parentDate', $parentModified = Factory::getDate($parentModified)->toSql()); } @@ -1226,11 +1230,13 @@ private function _setParentItem($language) $query->set($db->quoteName('parent_date') . ' = NULL'); } - $query->where([ - $db->quoteName('id') . ' <> :id', - $db->quoteName('key') . ' = :key', - $db->quoteName('context') . ' = :context' - ]) + $query->where( + [ + $db->quoteName('id') . ' <> :id', + $db->quoteName('key') . ' = :key', + $db->quoteName('context') . ' = :context' + ] + ) ->bind(':parentId', $parentId, ParameterType::INTEGER) ->bind(':id', $parentId, ParameterType::INTEGER) ->bind(':key', $value) From f8866a2fd6b686ef318fdbf080ae7c637bd3d885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Wed, 21 Aug 2019 17:40:31 +0200 Subject: [PATCH 85/98] fix bug for correct parent_date when adding child from other association When adding a child from another association, the parent_date for this child wasn't updated to the parent_date of the new association. This is fixed now. The key of each item before saving this association is compared with each other, in order to be able to check, if the item comes from another association and to update then the parent_date. --- .../Helper/AssociationsHelper.php | 4 ++-- .../Helper/DefaultAssocLangHelper.php | 20 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/administrator/components/com_associations/Helper/AssociationsHelper.php b/administrator/components/com_associations/Helper/AssociationsHelper.php index 70ec6be46d60e..424d6579efea8 100644 --- a/administrator/components/com_associations/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/Helper/AssociationsHelper.php @@ -360,8 +360,8 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId if (array_key_exists($items[$langCode]['id'], $assocParentDates) && array_key_exists($parentId, $assocParentDates)) { - $associatedModifiedParent = $assocParentDates[$items[$langCode]['id']]; - $lastModifiedParent = $assocParentDates[$parentId]; + $associatedModifiedParent = $assocParentDates[$items[$langCode]['id']][0]; + $lastModifiedParent = $assocParentDates[$parentId][0]; if ($associatedModifiedParent < $lastModifiedParent) { diff --git a/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php b/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php index 41f2c76859633..9e30cab18fce5 100644 --- a/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php +++ b/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php @@ -82,7 +82,7 @@ public static function getParentDates($associations, $context) } $query = $db->getQuery(true) - ->select($db->quoteName('parent_date')) + ->select($db->quoteName(['parent_date', 'key'])) ->from($db->quoteName('#__associations')) ->where( [ @@ -93,7 +93,7 @@ public static function getParentDates($associations, $context) ->bind(':id', $id, ParameterType::INTEGER) ->bind(':context', $context); $db->setQuery($query); - $parentDates[$id] = $db->loadResult(); + $parentDates[$id] = $db->loadRow(); } return $parentDates; @@ -129,12 +129,16 @@ public static function getParentValues($id, $dataId, $parentId, $parentModified, { $parentIdValue = $parentId; - // If modified date isn't set to the child item, set current modified date from parent. - $parentDateValue = empty($assocParentDates[$id]) + // If modified date isn't set to the child item, set current modified date from parent OR if child is added from another association + $parentDateValue = ( + empty($assocParentDates[$id][0]) + || ($assocParentDates[$id][1] !== $old_key) + || ($assocParentDates[$parentId][1] !== $assocParentDates[$id][1]) + ) ? $parentModified - : $assocParentDates[$id]; + : $assocParentDates[$id][0]; - if (!$old_key && ($dataId === $id)) + if (!$old_key && ($dataId !== $id)) { // Add modified date from parent to new associated item $parentDateValue = $parentModified ?? 'NULL'; @@ -243,8 +247,8 @@ public static function setParentAndChildInfos($itemId, $items, $key, $item, $def // Get association state of child when a parent item exists if ($parentId && (array_key_exists($key, $assocParentDates)) && (array_key_exists($parentId, $assocParentDates))) { - $associatedModifiedParent = $assocParentDates[$key]; - $lastModifiedParent = $assocParentDates[$parentId]; + $associatedModifiedParent = $assocParentDates[$key][0]; + $lastModifiedParent = $assocParentDates[$parentId][0]; if ($associatedModifiedParent < $lastModifiedParent) { From 1b14de032fa8aee7e8d062f965f36a11eac422cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Thu, 22 Aug 2019 19:11:15 +0200 Subject: [PATCH 86/98] Update administrator/components/com_associations/Model/AssociationsModel.php remove quote for integer constants Co-Authored-By: Harald Leithner --- .../components/com_associations/Model/AssociationsModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 6e76d4e36ecf5..2f87bcb21f3d3 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -469,7 +469,7 @@ protected function getListQuery() // Join over associations where id does not exist $query->where('((' . $db->quoteName('asso.id') . ' IS NULL )' // Or if we are on the child language and there is no parent - . ' OR ( ' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quote('-1') . ')' + . ' OR ( ' . $db->quoteName('asso2.parent_id') . ' = -1)' // Or a child of the parent does not exist. . ' OR ( ' . $db->quoteName('asso.key') . ' IN (' . $assocQuery . ') AND ' . $db->quoteName('asso.parent_id') . ' = ' . $db->quote('0') . ')' From 41d85a743ef32ec75760d82b69be06a3f326bddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Thu, 22 Aug 2019 19:11:37 +0200 Subject: [PATCH 87/98] Update administrator/components/com_associations/Model/AssociationsModel.php remove quote for integer constants Co-Authored-By: Harald Leithner --- .../components/com_associations/Model/AssociationsModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 2f87bcb21f3d3..2f21c38d06323 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -472,7 +472,7 @@ protected function getListQuery() . ' OR ( ' . $db->quoteName('asso2.parent_id') . ' = -1)' // Or a child of the parent does not exist. . ' OR ( ' . $db->quoteName('asso.key') . ' IN (' . $assocQuery . ') - AND ' . $db->quoteName('asso.parent_id') . ' = ' . $db->quote('0') . ')' + AND ' . $db->quoteName('asso.parent_id') . ' = 0)' . ')' ); } From b4d0019d95192b2bd81964490c5b7fafe50953db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Fri, 23 Aug 2019 10:09:46 +0200 Subject: [PATCH 88/98] use getContentLanguage method to count languages --- .../com_associations/Model/AssociationsModel.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index 2f21c38d06323..ad3e672c28012 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -14,6 +14,7 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Language\Associations; +use Joomla\CMS\Language\LanguageHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\CMS\MVC\Model\ListModel; @@ -453,18 +454,14 @@ protected function getListQuery() // Not associated if ($assocStateField === 'not_associated') { - $languageQuery = $db->getQuery(true) - ->select('COUNT(*)') - ->from($db->quoteName('#__languages')); - $db->setQuery($languageQuery); - $countLanguages = $db->loadResult(); + $countContentLanguages = count(LanguageHelper::getContentLanguages(array(0, 1))); // Get all keys where not all languages are associated. $assocQuery = $db->getQuery(true) ->select($db->quoteName('key')) ->from($db->quoteName('#__associations')) ->group($db->quoteName('key')) - ->having('COUNT(*) < ' . $countLanguages); + ->having('COUNT(*) < ' . $countContentLanguages); // Join over associations where id does not exist $query->where('((' . $db->quoteName('asso.id') . ' IS NULL )' From 5c9d903fc7132294855a51cd6c6c35df976b5184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Fri, 23 Aug 2019 10:50:06 +0200 Subject: [PATCH 89/98] use prepared statement and bind variable to the main query --- .../components/com_associations/Model/AssociationsModel.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_associations/Model/AssociationsModel.php b/administrator/components/com_associations/Model/AssociationsModel.php index ad3e672c28012..31a3c3a8cdbb5 100644 --- a/administrator/components/com_associations/Model/AssociationsModel.php +++ b/administrator/components/com_associations/Model/AssociationsModel.php @@ -461,7 +461,7 @@ protected function getListQuery() ->select($db->quoteName('key')) ->from($db->quoteName('#__associations')) ->group($db->quoteName('key')) - ->having('COUNT(*) < ' . $countContentLanguages); + ->having('COUNT(*) < :count'); // Join over associations where id does not exist $query->where('((' . $db->quoteName('asso.id') . ' IS NULL )' @@ -471,7 +471,8 @@ protected function getListQuery() . ' OR ( ' . $db->quoteName('asso.key') . ' IN (' . $assocQuery . ') AND ' . $db->quoteName('asso.parent_id') . ' = 0)' . ')' - ); + ) + ->bind(':count', $countContentLanguages, ParameterType::INTEGER); } // Out-of-date From 4e7e99f3630bbca193aad10485c405e1347ec262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sat, 24 Aug 2019 15:58:31 +0200 Subject: [PATCH 90/98] declare variable before running the loop --- .../com_associations/Helper/DefaultAssocLangHelper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php b/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php index 9e30cab18fce5..958ffcb217cb8 100644 --- a/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php +++ b/administrator/components/com_associations/Helper/DefaultAssocLangHelper.php @@ -72,7 +72,8 @@ public static function addNotAssociatedParentLink($defaultAssocLang, $itemId, $i */ public static function getParentDates($associations, $context) { - $db = Factory::getDbo(); + $parentDates = []; + $db = Factory::getDbo(); foreach ($associations as $langCode => $id) { From a596d3a5cfdbee3c6864f36f44c73735166cb50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= <31204883+lavipr@users.noreply.github.com> Date: Sat, 24 Aug 2019 18:31:39 +0200 Subject: [PATCH 91/98] Update plugins/system/languagefilter/languagefilter.php Fix PHP Notice: Undefined property: stdClass::$item_associations Co-Authored-By: Richard Fath --- plugins/system/languagefilter/languagefilter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index fbaf7dcc51c90..2f39617c49011 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -986,7 +986,7 @@ public function onExtensionBeforeSave($context, $table) $params = json_decode($table->params); $tableElement = $table->element; $pluginStatus = $table->enabled; - $itemAssocStatus = $params->item_associations; + $itemAssocStatus = $params->item_associations ?? false; if ($context != 'com_plugins.plugin' && $tableElement != 'languagefilter') { From f5b6dcb3b1ec6f6511fce747377d826189935da3 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 24 Aug 2019 18:47:00 +0200 Subject: [PATCH 92/98] Fix PHP notices in languagefilter.php --- .../system/languagefilter/languagefilter.php | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index 2f39617c49011..735b21ac6ce96 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -982,17 +982,23 @@ private function getLanguageCookie() */ public function onExtensionBeforeSave($context, $table) { - // Get the parameters which are to be saved. - $params = json_decode($table->params); + if ($context != 'com_plugins.plugin') + { + return true; + } + $tableElement = $table->element; - $pluginStatus = $table->enabled; - $itemAssocStatus = $params->item_associations ?? false; - if ($context != 'com_plugins.plugin' && $tableElement != 'languagefilter') + if ($tableElement != 'languagefilter') { return true; } + // Get the parameters which are to be saved. + $params = json_decode($table->params); + $pluginStatus = $table->enabled; + $itemAssocStatus = $params->item_associations ?? false; + // If the plugin and the parameter item_associations are enabled then set the correct value for the default association language. if ($pluginStatus && $itemAssocStatus) { @@ -1026,15 +1032,21 @@ public function onExtensionBeforeSave($context, $table) */ public function onExtensionAfterSave($context, $table) { - // Get the parameters which have been saved - $params = json_decode($table->params); + if ($context != 'com_plugins.plugin') + { + return true; + } + $tableElement = $table->element; - if ($context != 'com_plugins.plugin' && $tableElement != 'languagefilter') + if ($tableElement != 'languagefilter') { return true; } + // Get the parameters which have been saved + $params = json_decode($table->params); + // Only set association parent items if the default association language has changed. if ($this->hasAssocLangChanged) { From 18440277f207a45317d1524474fed51c2565b3cc Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 24 Aug 2019 18:50:26 +0200 Subject: [PATCH 93/98] PHPCS, type-safe comparison --- plugins/system/languagefilter/languagefilter.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index 735b21ac6ce96..8302a30873472 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -982,14 +982,14 @@ private function getLanguageCookie() */ public function onExtensionBeforeSave($context, $table) { - if ($context != 'com_plugins.plugin') + if ($context !== 'com_plugins.plugin') { return true; } - $tableElement = $table->element; + $tableElement = $table->element; - if ($tableElement != 'languagefilter') + if ($tableElement !== 'languagefilter') { return true; } @@ -1032,20 +1032,20 @@ public function onExtensionBeforeSave($context, $table) */ public function onExtensionAfterSave($context, $table) { - if ($context != 'com_plugins.plugin') + if ($context !== 'com_plugins.plugin') { return true; } $tableElement = $table->element; - if ($tableElement != 'languagefilter') + if ($tableElement !== 'languagefilter') { return true; } // Get the parameters which have been saved - $params = json_decode($table->params); + $params = json_decode($table->params); // Only set association parent items if the default association language has changed. if ($this->hasAssocLangChanged) From ac231c80a61eb7c8ac32242669ac65bc35398141 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 24 Aug 2019 19:47:25 +0200 Subject: [PATCH 94/98] Fix PHP Notice "Only variables ... by reference" in languagefilter.php --- plugins/system/languagefilter/languagefilter.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index 8302a30873472..9612a92a13402 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -1187,6 +1187,8 @@ private function _setParentItem($language) ->bind(':id', $parentId, ParameterType::INTEGER); $parentModified = $db->setQuery($parentModQuery)->loadResult(); } + + $parentModifiedSql = Factory::getDate($parentModified)->toSql(); } $parentId = $parentId ?? -1; @@ -1199,7 +1201,7 @@ private function _setParentItem($language) if ($modified) { $query->set($db->quoteName('parent_date') . ' = :parentDate') - ->bind(':parentDate', $parentModified = Factory::getDate($parentModified)->toSql()); + ->bind(':parentDate', $parentModifiedSql); } else { @@ -1235,7 +1237,7 @@ private function _setParentItem($language) if ($modified) { $query->set($db->quoteName('parent_date') . ' = :parentDate') - ->bind(':parentDate', $parentModified = Factory::getDate($parentModified)->toSql()); + ->bind(':parentDate', $parentModifiedSql); } else { From ffc4e279314c507e328100dd31408993ba2c5d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sat, 24 Aug 2019 22:57:34 +0200 Subject: [PATCH 95/98] fix controller name with correct casing Namespaced classes are case sensitive on case sensitive filesystems - like linux. --- .../components/com_associations/View/Association/HtmlView.php | 2 +- build/media_source/com_associations/js/sidebysideupdate.es6.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_associations/View/Association/HtmlView.php b/administrator/components/com_associations/View/Association/HtmlView.php index 1f8b3efb937fd..29ba8360c1be8 100644 --- a/administrator/components/com_associations/View/Association/HtmlView.php +++ b/administrator/components/com_associations/View/Association/HtmlView.php @@ -245,7 +245,7 @@ protected function addToolbar() // And when saving the target this button gets activated via js to update the parent's date for the child $toolbar->appendButton( 'Custom', '', 'target' + onclick="Joomla.submitbutton(\'defaultAssocLang.update\')">', 'target' ); } else diff --git a/build/media_source/com_associations/js/sidebysideupdate.es6.js b/build/media_source/com_associations/js/sidebysideupdate.es6.js index 6b25c5beadca3..65834eeaf8404 100644 --- a/build/media_source/com_associations/js/sidebysideupdate.es6.js +++ b/build/media_source/com_associations/js/sidebysideupdate.es6.js @@ -16,7 +16,7 @@ Joomla = window.Joomla || {}; // Using close button, normal joomla submit. if (task === 'association.cancel') { Joomla.submitform(task); - } else if (task === 'defaultassoclang.update') { + } else if (task === 'defaultAssocLang.update') { Joomla.submitform(task); } else { window.frames['target-association'].Joomla.submitbutton(`${document.getElementById('adminForm').getAttribute('data-associatedview')}, .apply`); From 6dcae085d8071c93d3e432e32000b1b79237213a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lavinia=20Popa-R=C3=B6ssel?= Date: Sat, 24 Aug 2019 23:44:31 +0200 Subject: [PATCH 96/98] fix model call name with correct casing Namespaced classes are case sensitive on case sensitive filesystems - like linux. --- .../com_associations/Controller/DefaultAssocLangController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Controller/DefaultAssocLangController.php b/administrator/components/com_associations/Controller/DefaultAssocLangController.php index 361ceac1f9e8f..843ef07ed4a37 100644 --- a/administrator/components/com_associations/Controller/DefaultAssocLangController.php +++ b/administrator/components/com_associations/Controller/DefaultAssocLangController.php @@ -34,7 +34,7 @@ public function update() $parentId = $this->input->get('id', '', 'int'); $itemtype = $this->input->get('itemtype', '', 'string'); - $this->getModel('defaultassoclang')->update($targetId, $parentId, $itemtype); + $this->getModel('defaultAssocLang')->update($targetId, $parentId, $itemtype); $this->setRedirect(Route::_('index.php?option=com_associations&view=associations', false)); } From 0023d729e2ef1edb172c4880aa1d7d9c8bdc47b1 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 24 Aug 2019 23:52:52 +0200 Subject: [PATCH 97/98] Fix PHP Notice "Only variables ... by reference" in DefaultAssocLangModel.php on line 70 --- .../com_associations/Model/DefaultAssocLangModel.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Model/DefaultAssocLangModel.php b/administrator/components/com_associations/Model/DefaultAssocLangModel.php index 44a757dc9df1f..038262983bf82 100644 --- a/administrator/components/com_associations/Model/DefaultAssocLangModel.php +++ b/administrator/components/com_associations/Model/DefaultAssocLangModel.php @@ -56,6 +56,7 @@ public function update($childId, $parentId, $itemtype) ->bind(':id', $parentId, ParameterType::INTEGER) ->bind(':context', $context); $parentModified = $db->setQuery($subQuery)->loadResult(); + $parentModifiedSql = Factory::getDate($parentModified)->toSql() $query = $db->getQuery(true) ->update($db->quoteName('#__associations')) @@ -67,7 +68,7 @@ public function update($childId, $parentId, $itemtype) $db->quoteName('context') . ' = :context' ] ) - ->bind(':parent_date', $parentModified = Factory::getDate($parentModified)->toSql()) + ->bind(':parent_date', $parentModifiedSql) ->bind(':id', $childId, ParameterType::INTEGER) ->bind(':parent_id', $parentId, ParameterType::INTEGER) ->bind(':context', $context); From 062dd08268cea159cbbc16fe03054306585fc53b Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 25 Aug 2019 00:02:18 +0200 Subject: [PATCH 98/98] Add missing semicolon --- .../components/com_associations/Model/DefaultAssocLangModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_associations/Model/DefaultAssocLangModel.php b/administrator/components/com_associations/Model/DefaultAssocLangModel.php index 038262983bf82..5fe957cf57e45 100644 --- a/administrator/components/com_associations/Model/DefaultAssocLangModel.php +++ b/administrator/components/com_associations/Model/DefaultAssocLangModel.php @@ -56,7 +56,7 @@ public function update($childId, $parentId, $itemtype) ->bind(':id', $parentId, ParameterType::INTEGER) ->bind(':context', $context); $parentModified = $db->setQuery($subQuery)->loadResult(); - $parentModifiedSql = Factory::getDate($parentModified)->toSql() + $parentModifiedSql = Factory::getDate($parentModified)->toSql(); $query = $db->getQuery(true) ->update($db->quoteName('#__associations'))