@@ -69,16 +68,16 @@
escape($item->language); ?>
|
- association)) : ?>
- association['title']; ?>
- typeFields['alias'])) : ?>
+ item_title)) : ?>
+ item_title; ?>
+ typeFields['alias'])) : ?>
- escape($item->association['alias'])); ?>
+ escape($item->alias)); ?>
typeFields['catid'])) : ?>
- escape($item->association['catid']); ?>
+ escape($item->category); ?>
From 5510ac3baea3b98c15207f1b63522e829d204f84 Mon Sep 17 00:00:00 2001
From: GraySmog <18949832421@163.com>
Date: Tue, 29 May 2018 16:59:32 +0800
Subject: [PATCH 05/15] Use function to remove field in filter form.
---
.../com_associations/View/Auto/HtmlView.php | 30 +++++++++++--------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/administrator/components/com_associations/View/Auto/HtmlView.php b/administrator/components/com_associations/View/Auto/HtmlView.php
index c4a27b7b88..f3502e17f1 100644
--- a/administrator/components/com_associations/View/Auto/HtmlView.php
+++ b/administrator/components/com_associations/View/Auto/HtmlView.php
@@ -128,28 +128,19 @@ public function display($tpl = null)
// Remove filters options depending on selected type.
if (empty($support['state']))
{
- unset($this->activeFilters['state']);
- $this->filterForm->removeField('state', 'filter');
+ $this->removeFilterField('state');
}
if (empty($support['category']))
{
- unset($this->activeFilters['category_id']);
- $this->filterForm->removeField('category_id', 'filter');
+ $this->removeFilterField('category_id');
}
if ($extensionName !== 'com_menus')
{
- unset($this->activeFilters['menutype']);
- $this->filterForm->removeField('menutype', 'filter');
- }
- if (empty($support['level']))
- {
- unset($this->activeFilters['level']);
- $this->filterForm->removeField('level', 'filter');
+ $this->removeFilterField('menutype');
}
if (empty($support['acl']))
{
- unset($this->activeFilters['access']);
- $this->filterForm->removeField('access', 'filter');
+ $this->removeFilterField('access');
}
// Add extension attribute to category filter.
@@ -171,4 +162,17 @@ public function display($tpl = null)
parent::display($tpl);
}
}
+
+ /**
+ * @param string $fieldname The field name to be removed in the filter form.
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ private function removeFilterField($fieldname)
+ {
+ unset($this->activeFilters[$fieldname]);
+ $this->filterForm->removeField($fieldname, 'filter');
+ }
}
From 948e4f5e827bf24d21f84d56ee77d89560fafcc7 Mon Sep 17 00:00:00 2001
From: GraySmog <18949832421@163.com>
Date: Sun, 3 Jun 2018 02:17:04 +0800
Subject: [PATCH 06/15] Create associations of current article by selected
languages
---
.../com_associations/Model/AutoModel.php | 6 +-
.../com_associations/forms/filter_auto.xml | 10 -
.../Controller/ArticleController.php | 30 +++
.../com_content/Model/ArticleModel.php | 177 ++++++++++++++++++
.../src/MVC/Controller/FormController.php | 38 ++++
5 files changed, 248 insertions(+), 13 deletions(-)
diff --git a/administrator/components/com_associations/Model/AutoModel.php b/administrator/components/com_associations/Model/AutoModel.php
index b0bef475d9..306acae41e 100644
--- a/administrator/components/com_associations/Model/AutoModel.php
+++ b/administrator/components/com_associations/Model/AutoModel.php
@@ -203,7 +203,7 @@ protected function getListQuery()
->select($db->quoteName('l.image', 'language_image'))
->join(
'RIGHT', $db->quoteName('#__languages', 'l') . ' ON c2.'
- . $db->quoteName($langField) . ' = l.lang_code'
+ . $db->quoteName($langField) . ' = ' . $db->quoteName('l.lang_code')
);
// Use alias field ?
@@ -238,12 +238,12 @@ protected function getListQuery()
}
$query->where('(c.' . $pk . ' = ' . (int) $referenceId . ' OR c.' . $pk . ' IS NULL) AND (c.'
- . $langField . ' != l.lang_code OR c.' . $langField . ' IS NULL)'
+ . $langField . ' != ' . $db->quoteName('l.lang_code') . ' OR c.' . $langField . ' IS NULL)'
);
if ($tablename === '#__categories')
{
- $query->where('c.extension = ' . $db->quote($extensionName));
+ $query->where($db->quoteName('c.extension') . ' = ' . $db->quote($extensionName));
}
return $query;
diff --git a/administrator/components/com_associations/forms/filter_auto.xml b/administrator/components/com_associations/forms/filter_auto.xml
index 63f10e0327..f806a52e47 100644
--- a/administrator/components/com_associations/forms/filter_auto.xml
+++ b/administrator/components/com_associations/forms/filter_auto.xml
@@ -62,16 +62,6 @@
-
-
-
diff --git a/administrator/components/com_content/Controller/ArticleController.php b/administrator/components/com_content/Controller/ArticleController.php
index 578e30f0f2..ef82b6a36e 100644
--- a/administrator/components/com_content/Controller/ArticleController.php
+++ b/administrator/components/com_content/Controller/ArticleController.php
@@ -121,6 +121,36 @@ protected function allowEdit($data = array(), $key = 'id')
return false;
}
+ /**
+ * Method to automatically create associated articles.
+ *
+ * @param BaseDatabaseModel $model The model of the component being processed.
+ *
+ * @return boolean True is successful, false otherwise and internal error is set.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function autocreate($model = null)
+ {
+ \JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));
+
+ if (!Associations::isEnabled())
+ {
+ // @TODO Add Error Messages
+ $this->setMessage(Text::_(''));
+
+ return false;
+ }
+
+ // Set the model
+ $model = $this->getModel('Article', 'Administrator', array());
+
+ // Preset the redirect
+ $this->setRedirect(\JRoute::_('index.php?option=com_content&view=articles' . $this->getRedirectToListAppend(), false));
+
+ return parent::autocreate($model);
+ }
+
/**
* Method to run batch operations.
*
diff --git a/administrator/components/com_content/Model/ArticleModel.php b/administrator/components/com_content/Model/ArticleModel.php
index 4d986f15c5..8638b477a6 100644
--- a/administrator/components/com_content/Model/ArticleModel.php
+++ b/administrator/components/com_content/Model/ArticleModel.php
@@ -14,6 +14,7 @@
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;
use Joomla\CMS\MVC\Model\AdminModel;
+use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper;
/**
* Item Model for an Article.
@@ -46,6 +47,182 @@ class ArticleModel extends AdminModel
*/
protected $associationsContext = 'com_content.item';
+ /**
+ * Method to automatically create associations of an item in chosen languages.
+ *
+ * @param int $itemId Id of current item.
+ * @param array $cid An array of language ids.
+ *
+ * @return boolean Return true on success, false on failure.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function autocreate($itemId, $cid)
+ {
+ // Sanitize ids.
+ $cid = array_unique($cid);
+ $cid = ArrayHelper::toInteger($cid);
+
+ // Remove any values of zero.
+ if (array_search(0, $cid, true))
+ {
+ unset($cid[array_search(0, $cid, true)]);
+ }
+
+ if (empty($cid))
+ {
+ $this->setError(\JText::_('JGLOBAL_NO_ITEM_SELECTED'));
+
+ return false;
+ }
+
+ // Get associations
+ $associations = AssociationsHelper::getAssociationList('com_content', 'article', $itemId);
+
+ // Get current user
+ if (empty($this->user))
+ {
+ $this->user = \JFactory::getUser();
+ }
+
+ // Get content table
+ if (empty($this->table))
+ {
+ $this->table = $this->getTable();
+ }
+
+ // Get language table
+ $languageTable = $this->getTable('Language', 'Joomla\CMS\Table');
+
+ while (!empty($cid))
+ {
+ // Pop the first ID off the stack
+ $pk = array_shift($cid);
+
+ $this->table->reset();
+ $languageTable->reset();
+
+ if (!$languageTable->load($pk) || !$this->table->load($itemId))
+ {
+ if ($error = $languageTable->getError())
+ {
+ // Fatal error
+ $this->setError($error);
+
+ return false;
+ }
+ elseif ($error = $this->table->getError())
+ {
+ // Fatal error
+ $this->setError($error);
+
+ return false;
+ }
+ else
+ {
+ // @TODO Add 'JLIB_APPLICATION_ERROR_AUTO_ASSOCIATIONS_ROW_NOT_FOUND'
+ // Not fatal error
+ $this->setError(\JText::sprintf('', $pk));
+ continue;
+ }
+ }
+
+ // Get current language
+ $lang_code = $languageTable->lang_code;
+
+ // If the article doesn't have associations in current language
+ if (!isset($associations[$lang_code]))
+ {
+ // Alter the title & alias
+ $this->table->title .= ' [' . $lang_code . ']';
+ $this->table->alias .= ' [' . $lang_code . ']';
+
+ // Alter the language
+ $this->table->language = $lang_code;
+
+ // Reset the ID, hits, state.
+ $this->table->id = $this->table->hits = $this->table->state = 0;
+
+ // @TODO Change category?
+
+ // Get the featured state
+ $featured = $this->table->featured;
+
+ // Check the row.
+ if (!$this->table->check())
+ {
+ $this->setError($this->table->getError());
+
+ return false;
+ }
+
+ // Store the row.
+ if (!$this->table->store())
+ {
+ $this->setError($this->table->getError());
+
+ return false;
+ }
+
+ // Get the new item ID
+ $newId = $this->table->get('id');
+
+ // Check if the article was featured and update the #__content_frontpage table
+ if ($featured == 1)
+ {
+ $db = $this->getDbo();
+ $query = $db->getQuery(true)
+ ->insert($db->quoteName('#__content_frontpage'))
+ ->values($newId . ', 0');
+ $db->setQuery($query);
+ $db->execute();
+ }
+ }
+ }
+
+ // Get associations key for edited item
+ $db = $this->getDbo();
+ $query = $db->getQuery(true)
+ ->select($db->quoteName('key'))
+ ->from($db->quoteName('#__associations'))
+ ->where($db->quoteName('context') . ' = ' . $db->quote('com_content.item'))
+ ->where($db->quoteName('id') . ' = ' . (int) $itemId);
+ $db->setQuery($query);
+ $oldKey = $db->loadResult();
+
+ // Deleting old associations for the associated items
+ $query = $db->getQuery(true)
+ ->delete($db->quoteName('#__associations'))
+ ->where('(' . $db->quoteName('context') . ' = ' . $db->quote('.item') . ') AND ('
+ . $db->quoteName('key') . ' = ' . $db->quote($oldKey) . ')'
+ );
+
+ $db->setQuery($query);
+ $db->execute();
+
+ // Add new associations
+ if (count($associations) > 1)
+ {
+ // Adding new association for these items
+ $key = md5(json_encode($associations));
+ $query = $db->getQuery(true)
+ ->insert('#__associations');
+
+ foreach ($associations as $data)
+ {
+ $query->values(((int) $data['id']) . ',' . $db->quote('com_content.item') . ',' . $db->quote($key));
+ }
+
+ $db->setQuery($query);
+ $db->execute();
+ }
+
+ // Clean the cache
+ $this->cleanCache();
+
+ return true;
+ }
+
/**
* Batch copy items to a new category or current.
*
diff --git a/libraries/src/MVC/Controller/FormController.php b/libraries/src/MVC/Controller/FormController.php
index 747c828277..055a25a1d3 100644
--- a/libraries/src/MVC/Controller/FormController.php
+++ b/libraries/src/MVC/Controller/FormController.php
@@ -241,6 +241,44 @@ protected function allowSave($data, $key = 'id')
}
}
+ /**
+ * Method to automatically create associated articles.
+ *
+ * @param BaseDatabaseModel $model The model of the component being processed.
+ *
+ * @return boolean True is successful, false otherwise and internal error is set.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function autocreate($model)
+ {
+ $cid = $this->input->post->get('cid', array(), 'array');
+ $itemId = $this->input->post->get('id', array(), 'INT');
+
+ if (!Associations::isEnabled())
+ {
+ // @TODO Add Error Messages
+ $this->setMessage(Text::_(''));
+
+ return false;
+ }
+
+ if ($model->autocreate($itemId, $cid))
+ {
+ // @TODO Add 'JLIB_APPLICATION_SUCCESS_AUTO_ASSOCIATIONS'
+ $this->setMessage(Text::_(''));
+
+ return true;
+ }
+ else
+ {
+ // @TODO Add 'JLIB_APPLICATION_ERROR_AUTO_ASSOCIATIONS_FAILED'
+ $this->setMessage(Text::_(''));
+
+ return false;
+ }
+ }
+
/**
* Method to run batch operations.
*
From 92199a762935109d3ed7cc8e96b3372d88854117 Mon Sep 17 00:00:00 2001
From: GraySmog <18949832421@163.com>
Date: Wed, 6 Jun 2018 00:19:12 +0800
Subject: [PATCH 07/15] Update query statements in getListQuery()
---
.../com_associations/Model/AutoModel.php | 139 +++++++++++-------
1 file changed, 82 insertions(+), 57 deletions(-)
diff --git a/administrator/components/com_associations/Model/AutoModel.php b/administrator/components/com_associations/Model/AutoModel.php
index 306acae41e..406a4ddc6c 100644
--- a/administrator/components/com_associations/Model/AutoModel.php
+++ b/administrator/components/com_associations/Model/AutoModel.php
@@ -175,75 +175,100 @@ protected function getListQuery()
$fields = $details['fields'];
- $tablename = $details['tables']['a'];
- $referenceId = $this->state->get('referenceId');
- $context = $extensionName . '.item';
- $pk = explode('.', $fields['id'])[1];
- $titleField = explode('.', $fields['title'])[1];
- $langField = explode('.', $fields['language'])[1];
+ $tablename = $details['tables']['a'];
+ $referenceId = $this->state->get('referenceId');
+ $context = $extensionName . '.item';
+ $pk = explode('.', $fields['id'])[1];
+ $titleField = explode('.', $fields['title'])[1];
+ $langField = explode('.', $fields['language'])[1];
+ $associations = AssociationsHelper::getAssociationList($extensionName, $typeName, $referenceId);
if ($typeName === 'category')
{
$context = 'com_categories.item';
}
- $categoriesExtraSql = (($tablename === '#__categories') ? ' AND c2.extension = ' . $db->quote($extensionName) : '');
-
- $query->select($db->quoteName('c2.' . $pk, 'item_id'))
- ->select($db->quoteName('c2.' . $titleField, 'item_title'))
- ->from($db->quoteName($tablename, 'c'))
- ->join('INNER', $db->quoteName('#__associations', 'a') . ' ON a.id = c.' . $db->quoteName($pk) . ' AND a.context=' . $db->quote($context))
- ->join('INNER', $db->quoteName('#__associations', 'a2') . ' ON a.key = a2.key')
- ->join('INNER', $db->quoteName($tablename, 'c2') . ' ON a2.id = c2.' . $db->quoteName($pk) . $categoriesExtraSql);
-
- $query->select($db->quoteName('l.lang_id', 'lang_id'))
- ->select($db->quoteName('l.lang_code', 'language'))
- ->select($db->quoteName('l.published', 'published'))
- ->select($db->quoteName('l.title', 'language_title'))
- ->select($db->quoteName('l.image', 'language_image'))
- ->join(
- 'RIGHT', $db->quoteName('#__languages', 'l') . ' ON c2.'
- . $db->quoteName($langField) . ' = ' . $db->quoteName('l.lang_code')
- );
-
- // Use alias field ?
- if (!empty($fields['alias']))
- {
- $aliasField = explode('.', $fields['alias'])[1];
-
- $query->select($db->quoteName('c2.' . $aliasField, 'alias'));
- }
-
- // Use catid field ?
- if (!empty($fields['catid']))
+ if (!empty($associations))
{
- $catField = explode('.', $fields['catid'])[1];
-
- $query->join('LEFT', $db->quoteName('#__categories', 'ca')
- . ' ON ' . $db->quoteName('c2.' . $catField) . ' = ca.id AND ca.extension = ' . $db->quote($extensionName)
- )
- ->select($db->quoteName('ca.alias', 'category'));
- }
-
- // If component item type supports menu type, select the menu type also.
- if (!empty($fields['menutype']))
- {
- $menutypeField = explode('.', $fields['menutype'])[1];
-
- $query->select($db->quoteName('mt.title', 'menutype_title'))
+ $categoriesExtraSql = (($tablename === '#__categories') ? ' AND c2.extension = ' . $db->quote($extensionName) : '');
+
+ $query->select($db->quoteName('c2.' . $pk, 'item_id'))
+ ->select($db->quoteName('c2.' . $titleField, 'item_title'))
+ ->from($db->quoteName($tablename, 'c'))
+ ->join('INNER', $db->quoteName('#__associations', 'a') . ' ON a.id = c.' . $db->quoteName($pk)
+ . ' AND a.context=' . $db->quote($context)
+ )
+ ->join('INNER', $db->quoteName('#__associations', 'a2') . ' ON a.key = a2.key')
+ ->join('INNER', $db->quoteName($tablename, 'c2') . ' ON a2.id = c2.' . $db->quoteName($pk) . $categoriesExtraSql);
+
+ $query->select($db->quoteName('l.lang_id', 'lang_id'))
+ ->select($db->quoteName('l.lang_code', 'language'))
+ ->select($db->quoteName('l.published', 'published'))
+ ->select($db->quoteName('l.title', 'language_title'))
+ ->select($db->quoteName('l.image', 'language_image'))
->join(
- 'LEFT', $db->quoteName('#__menu_types', 'mt') . ' ON ' . $db->quoteName('mt.menutype')
- . ' = ' . $db->quoteName('c2.' . $menutypeField)
+ 'RIGHT', $db->quoteName('#__languages', 'l') . ' ON ' . $db->quoteName('c2.' . $langField)
+ . ' = ' . $db->quoteName('l.lang_code')
);
- }
- $query->where('(c.' . $pk . ' = ' . (int) $referenceId . ' OR c.' . $pk . ' IS NULL) AND (c.'
- . $langField . ' != ' . $db->quoteName('l.lang_code') . ' OR c.' . $langField . ' IS NULL)'
- );
+ // Use alias field ?
+ if (!empty($fields['alias']))
+ {
+ $aliasField = explode('.', $fields['alias'])[1];
+
+ $query->select($db->quoteName('c2.' . $aliasField, 'alias'));
+ }
+
+ // Use catid field ?
+ if (!empty($fields['catid']))
+ {
+ $catField = explode('.', $fields['catid'])[1];
+
+ $query->join('LEFT', $db->quoteName('#__categories', 'ca')
+ . ' ON ' . $db->quoteName('c2.' . $catField) . ' = ca.id AND ca.extension = ' . $db->quote($extensionName)
+ )
+ ->select($db->quoteName('ca.alias', 'category'));
+ }
+
+ // If component item type supports menu type, select the menu type also.
+ if (!empty($fields['menutype']))
+ {
+ $menutypeField = explode('.', $fields['menutype'])[1];
+
+ $query->select($db->quoteName('mt.title', 'menutype_title'))
+ ->join(
+ 'LEFT', $db->quoteName('#__menu_types', 'mt') . ' ON ' . $db->quoteName('mt.menutype')
+ . ' = ' . $db->quoteName('c2.' . $menutypeField)
+ );
+ }
+
+ $query->where('(c.' . $pk . ' = ' . (int) $referenceId . ' OR c.' . $pk . ' IS NULL) AND (c.'
+ . $langField . ' != l.lang_code OR c.' . $langField . ' IS NULL)'
+ );
- if ($tablename === '#__categories')
+ if ($tablename === '#__categories')
+ {
+ $query->where($db->quoteName('c.extension') . ' = ' . $db->quote($extensionName));
+ }
+ }
+ else
{
- $query->where($db->quoteName('c.extension') . ' = ' . $db->quote($extensionName));
+ $tmpQuery = $db->getQuery(true);
+
+ $tmpQuery->select($db->quoteName('c.' . $langField))
+ ->from($db->quoteName($tablename, 'c'))
+ ->where($db->quoteName('c.' . $pk) . ' = ' . (int) $referenceId);
+
+ $db->setQuery($tmpQuery);
+ $ignored = $db->loadResult();
+
+ $query->select($db->quoteName('l.lang_id', 'lang_id'))
+ ->select($db->quoteName('l.lang_code', 'language'))
+ ->select($db->quoteName('l.published', 'published'))
+ ->select($db->quoteName('l.title', 'language_title'))
+ ->select($db->quoteName('l.image', 'language_image'))
+ ->from($db->quoteName('#__languages', 'l'))
+ ->where($db->quoteName('l.lang_code') . ' != ' . $db->quote($ignored));
}
return $query;
From 0bff96db4f169738cc359ff6f5d35491dd2379ca Mon Sep 17 00:00:00 2001
From: GraySmog <18949832421@163.com>
Date: Wed, 6 Jun 2018 16:57:58 +0800
Subject: [PATCH 08/15] Create associations by selected languages
---
.../Controller/AutoController.php | 53 +++++
.../com_associations/Model/AutoModel.php | 192 ++++++++++++++++++
.../com_associations/tmpl/auto/modal.php | 156 +++++++-------
.../Controller/ArticleController.php | 30 ---
.../com_content/Model/ArticleModel.php | 177 ----------------
.../src/MVC/Controller/FormController.php | 2 +-
6 files changed, 329 insertions(+), 281 deletions(-)
create mode 100644 administrator/components/com_associations/Controller/AutoController.php
diff --git a/administrator/components/com_associations/Controller/AutoController.php b/administrator/components/com_associations/Controller/AutoController.php
new file mode 100644
index 0000000000..ee84b81f1e
--- /dev/null
+++ b/administrator/components/com_associations/Controller/AutoController.php
@@ -0,0 +1,53 @@
+setMessage(Text::_(''));
+
+ return false;
+ }
+
+ // Set the model
+ $model = $this->getModel('Auto', 'Administrator', array());
+
+ // Preset the redirect
+ $this->setRedirect(\JRoute::_('index.php?option=com_content&view=articles' . $this->getRedirectToListAppend(), false));
+
+ return parent::autocreate($model);
+ }
+}
\ No newline at end of file
diff --git a/administrator/components/com_associations/Model/AutoModel.php b/administrator/components/com_associations/Model/AutoModel.php
index 406a4ddc6c..8bfc03e523 100644
--- a/administrator/components/com_associations/Model/AutoModel.php
+++ b/administrator/components/com_associations/Model/AutoModel.php
@@ -14,6 +14,8 @@
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\DatabaseQuery;
use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper;
+use Joomla\Utilities\ArrayHelper;
+use Joomla\CMS\Table\Table;
/**
* Methods supporting a list of article records.
@@ -55,6 +57,196 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu
parent::__construct($config, $factory);
}
+ /**
+ * Method to automatically create associations of an item in chosen languages.
+ *
+ * @param int $itemId Id of current item.
+ * @param array $cid An array of language ids.
+ *
+ * @return boolean Return true on success, false on failure.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function autocreate($itemId, $cid)
+ {
+ // Sanitize ids.
+ $cid = array_unique($cid);
+ $cid = ArrayHelper::toInteger($cid);
+
+ // Remove any values of zero.
+ if (array_search(0, $cid, true))
+ {
+ unset($cid[array_search(0, $cid, true)]);
+ }
+
+ if (empty($cid))
+ {
+ $this->setError(\JText::_('JGLOBAL_NO_ITEM_SELECTED'));
+
+ return false;
+ }
+
+ // Get associations
+ $associations = AssociationsHelper::getAssociationList('com_content', 'article', $itemId);
+
+ // Get current user
+ if (empty($this->user))
+ {
+ $this->user = \JFactory::getUser();
+ }
+
+ // Get content table
+ $contentTable = Table::getInstance('Content', 'Joomla\\CMS\\Table\\');
+
+ // Get language table
+ $languageTable = Table::getInstance('Language', 'Joomla\\CMS\\Table\\');
+
+ while (!empty($cid))
+ {
+ // Pop the first ID off the stack
+ $pk = array_shift($cid);
+
+ $contentTable->reset();
+ $languageTable->reset();
+
+ if (!$languageTable->load($pk) || !$contentTable->load($itemId))
+ {
+ if ($error = $languageTable->getError())
+ {
+ // Fatal error
+ $this->setError($error);
+
+ return false;
+ }
+ elseif ($error = $contentTable->getError())
+ {
+ // Fatal error
+ $this->setError($error);
+
+ return false;
+ }
+ else
+ {
+ // @TODO Add 'JLIB_APPLICATION_ERROR_AUTO_ASSOCIATIONS_ROW_NOT_FOUND'
+ // Not fatal error
+ $this->setError(\JText::sprintf('', $pk));
+ continue;
+ }
+ }
+
+ // Get current language
+ $langCode = $languageTable->lang_code;
+
+ if (!isset($itemLang))
+ {
+ $itemLang = $contentTable->language;
+ }
+
+ // If the article doesn't have associations in current language
+ if (!isset($associations[$langCode]))
+ {
+ // Alter the title & alias
+ $contentTable->title .= ' [' . $langCode . ']';
+ $contentTable->alias .= ' [' . $langCode . ']';
+
+ // Alter the language
+ $contentTable->language = $langCode;
+
+ // Reset the ID, hits, state.
+ $contentTable->id = $contentTable->hits = $contentTable->state = 0;
+
+ // @TODO Change category?
+
+ // Get the featured state
+ $featured = $contentTable->featured;
+
+ // Check the row.
+ if (!$contentTable->check())
+ {
+ $this->setError($contentTable->getError());
+
+ return false;
+ }
+
+ // Store the row.
+ if (!$contentTable->store())
+ {
+ $this->setError($contentTable->getError());
+
+ return false;
+ }
+
+ // Get the new item ID
+ $newId = $contentTable->getId();
+
+ // Check if the article was featured and update the #__content_frontpage table
+ if ($featured == 1)
+ {
+ $db = $this->getDbo();
+ $query = $db->getQuery(true)
+ ->insert($db->quoteName('#__content_frontpage'))
+ ->values($newId . ', 0');
+ $db->setQuery($query);
+ $db->execute();
+ }
+
+ // Add new item to associations
+ $associations[$langCode] = (int) $contentTable->getId();
+ }
+ else
+ {
+ $associations[$langCode] = (int) $associations[$langCode]['id'];
+ }
+ }
+
+ // Get associations key for edited item
+ $db = $this->getDbo();
+ $query = $db->getQuery(true)
+ ->select($db->quoteName('key'))
+ ->from($db->quoteName('#__associations'))
+ ->where($db->quoteName('context') . ' = ' . $db->quote('com_content.item'))
+ ->where($db->quoteName('id') . ' = ' . (int) $itemId);
+ $db->setQuery($query);
+ $oldKey = $db->loadResult();
+
+ // Deleting old associations for the associated items
+ $query = $db->getQuery(true)
+ ->delete($db->quoteName('#__associations'))
+ ->where('(' . $db->quoteName('context') . ' = ' . $db->quote('.item') . ') AND ('
+ . $db->quoteName('key') . ' = ' . $db->quote($oldKey) . ')'
+ );
+
+ $db->setQuery($query);
+ $db->execute();
+
+ if ($itemLang !== '*')
+ {
+ $associations[$itemLang] = (int) $itemId;
+ }
+
+ // Add new associations
+ if (count($associations) > 1)
+ {
+ // Adding new association for these items
+ $key = md5(json_encode($associations));
+ $query = $db->getQuery(true)
+ ->insert('#__associations');
+
+ foreach ($associations as $id)
+ {
+ $query->values(((int) $id) . ',' . $db->quote('com_content.item') . ',' . $db->quote($key));
+ }
+
+ $db->setQuery($query);
+ $db->execute();
+ }
+
+ // Clean the cache
+ $this->cleanCache();
+
+ return true;
+ }
+
/**
* Method to auto-populate the model state.
*
diff --git a/administrator/components/com_associations/tmpl/auto/modal.php b/administrator/components/com_associations/tmpl/auto/modal.php
index 01b871155d..e48b57c909 100644
--- a/administrator/components/com_associations/tmpl/auto/modal.php
+++ b/administrator/components/com_associations/tmpl/auto/modal.php
@@ -19,82 +19,92 @@
// @TODO add scripts
?>
-
+
+
\ No newline at end of file
diff --git a/administrator/components/com_content/Controller/ArticleController.php b/administrator/components/com_content/Controller/ArticleController.php
index ef82b6a36e..578e30f0f2 100644
--- a/administrator/components/com_content/Controller/ArticleController.php
+++ b/administrator/components/com_content/Controller/ArticleController.php
@@ -121,36 +121,6 @@ protected function allowEdit($data = array(), $key = 'id')
return false;
}
- /**
- * Method to automatically create associated articles.
- *
- * @param BaseDatabaseModel $model The model of the component being processed.
- *
- * @return boolean True is successful, false otherwise and internal error is set.
- *
- * @since __DEPLOY_VERSION__
- */
- public function autocreate($model = null)
- {
- \JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));
-
- if (!Associations::isEnabled())
- {
- // @TODO Add Error Messages
- $this->setMessage(Text::_(''));
-
- return false;
- }
-
- // Set the model
- $model = $this->getModel('Article', 'Administrator', array());
-
- // Preset the redirect
- $this->setRedirect(\JRoute::_('index.php?option=com_content&view=articles' . $this->getRedirectToListAppend(), false));
-
- return parent::autocreate($model);
- }
-
/**
* Method to run batch operations.
*
diff --git a/administrator/components/com_content/Model/ArticleModel.php b/administrator/components/com_content/Model/ArticleModel.php
index 8638b477a6..4d986f15c5 100644
--- a/administrator/components/com_content/Model/ArticleModel.php
+++ b/administrator/components/com_content/Model/ArticleModel.php
@@ -14,7 +14,6 @@
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;
use Joomla\CMS\MVC\Model\AdminModel;
-use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper;
/**
* Item Model for an Article.
@@ -47,182 +46,6 @@ class ArticleModel extends AdminModel
*/
protected $associationsContext = 'com_content.item';
- /**
- * Method to automatically create associations of an item in chosen languages.
- *
- * @param int $itemId Id of current item.
- * @param array $cid An array of language ids.
- *
- * @return boolean Return true on success, false on failure.
- *
- * @since __DEPLOY_VERSION__
- */
- public function autocreate($itemId, $cid)
- {
- // Sanitize ids.
- $cid = array_unique($cid);
- $cid = ArrayHelper::toInteger($cid);
-
- // Remove any values of zero.
- if (array_search(0, $cid, true))
- {
- unset($cid[array_search(0, $cid, true)]);
- }
-
- if (empty($cid))
- {
- $this->setError(\JText::_('JGLOBAL_NO_ITEM_SELECTED'));
-
- return false;
- }
-
- // Get associations
- $associations = AssociationsHelper::getAssociationList('com_content', 'article', $itemId);
-
- // Get current user
- if (empty($this->user))
- {
- $this->user = \JFactory::getUser();
- }
-
- // Get content table
- if (empty($this->table))
- {
- $this->table = $this->getTable();
- }
-
- // Get language table
- $languageTable = $this->getTable('Language', 'Joomla\CMS\Table');
-
- while (!empty($cid))
- {
- // Pop the first ID off the stack
- $pk = array_shift($cid);
-
- $this->table->reset();
- $languageTable->reset();
-
- if (!$languageTable->load($pk) || !$this->table->load($itemId))
- {
- if ($error = $languageTable->getError())
- {
- // Fatal error
- $this->setError($error);
-
- return false;
- }
- elseif ($error = $this->table->getError())
- {
- // Fatal error
- $this->setError($error);
-
- return false;
- }
- else
- {
- // @TODO Add 'JLIB_APPLICATION_ERROR_AUTO_ASSOCIATIONS_ROW_NOT_FOUND'
- // Not fatal error
- $this->setError(\JText::sprintf('', $pk));
- continue;
- }
- }
-
- // Get current language
- $lang_code = $languageTable->lang_code;
-
- // If the article doesn't have associations in current language
- if (!isset($associations[$lang_code]))
- {
- // Alter the title & alias
- $this->table->title .= ' [' . $lang_code . ']';
- $this->table->alias .= ' [' . $lang_code . ']';
-
- // Alter the language
- $this->table->language = $lang_code;
-
- // Reset the ID, hits, state.
- $this->table->id = $this->table->hits = $this->table->state = 0;
-
- // @TODO Change category?
-
- // Get the featured state
- $featured = $this->table->featured;
-
- // Check the row.
- if (!$this->table->check())
- {
- $this->setError($this->table->getError());
-
- return false;
- }
-
- // Store the row.
- if (!$this->table->store())
- {
- $this->setError($this->table->getError());
-
- return false;
- }
-
- // Get the new item ID
- $newId = $this->table->get('id');
-
- // Check if the article was featured and update the #__content_frontpage table
- if ($featured == 1)
- {
- $db = $this->getDbo();
- $query = $db->getQuery(true)
- ->insert($db->quoteName('#__content_frontpage'))
- ->values($newId . ', 0');
- $db->setQuery($query);
- $db->execute();
- }
- }
- }
-
- // Get associations key for edited item
- $db = $this->getDbo();
- $query = $db->getQuery(true)
- ->select($db->quoteName('key'))
- ->from($db->quoteName('#__associations'))
- ->where($db->quoteName('context') . ' = ' . $db->quote('com_content.item'))
- ->where($db->quoteName('id') . ' = ' . (int) $itemId);
- $db->setQuery($query);
- $oldKey = $db->loadResult();
-
- // Deleting old associations for the associated items
- $query = $db->getQuery(true)
- ->delete($db->quoteName('#__associations'))
- ->where('(' . $db->quoteName('context') . ' = ' . $db->quote('.item') . ') AND ('
- . $db->quoteName('key') . ' = ' . $db->quote($oldKey) . ')'
- );
-
- $db->setQuery($query);
- $db->execute();
-
- // Add new associations
- if (count($associations) > 1)
- {
- // Adding new association for these items
- $key = md5(json_encode($associations));
- $query = $db->getQuery(true)
- ->insert('#__associations');
-
- foreach ($associations as $data)
- {
- $query->values(((int) $data['id']) . ',' . $db->quote('com_content.item') . ',' . $db->quote($key));
- }
-
- $db->setQuery($query);
- $db->execute();
- }
-
- // Clean the cache
- $this->cleanCache();
-
- return true;
- }
-
/**
* Batch copy items to a new category or current.
*
diff --git a/libraries/src/MVC/Controller/FormController.php b/libraries/src/MVC/Controller/FormController.php
index 055a25a1d3..bd4677a8b2 100644
--- a/libraries/src/MVC/Controller/FormController.php
+++ b/libraries/src/MVC/Controller/FormController.php
@@ -253,7 +253,7 @@ protected function allowSave($data, $key = 'id')
public function autocreate($model)
{
$cid = $this->input->post->get('cid', array(), 'array');
- $itemId = $this->input->post->get('id', array(), 'INT');
+ $itemId = $this->input->post->get('id', array(), 'int');
if (!Associations::isEnabled())
{
From 3cc0d2a3ad2a1ae3d29df1be94a42f38f61a72b9 Mon Sep 17 00:00:00 2001
From: GraySmog <18949832421@163.com>
Date: Mon, 11 Jun 2018 00:16:07 +0800
Subject: [PATCH 09/15] Improve sql statements in AutoModel
---
.../com_associations/Model/AutoModel.php | 38 +++++++++----------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/administrator/components/com_associations/Model/AutoModel.php b/administrator/components/com_associations/Model/AutoModel.php
index 8bfc03e523..f1629cf618 100644
--- a/administrator/components/com_associations/Model/AutoModel.php
+++ b/administrator/components/com_associations/Model/AutoModel.php
@@ -310,7 +310,6 @@ protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('itemtype');
- $id .= ':' . $this->getState('forcedLanguage');
$id .= ':' . $this->getState('filter.search');
$id .= ':' . $this->getState('filter.state');
$id .= ':' . $this->getState('filter.category_id');
@@ -380,6 +379,15 @@ protected function getListQuery()
$context = 'com_categories.item';
}
+ $tmpQuery = $db->getQuery(true);
+
+ $tmpQuery->select($db->quoteName('c.' . $langField))
+ ->from($db->quoteName($tablename, 'c'))
+ ->where($db->quoteName('c.' . $pk) . ' = ' . (int) $referenceId);
+
+ $db->setQuery($tmpQuery);
+ $ignored = $db->loadResult();
+
if (!empty($associations))
{
$categoriesExtraSql = (($tablename === '#__categories') ? ' AND c2.extension = ' . $db->quote($extensionName) : '');
@@ -387,11 +395,13 @@ protected function getListQuery()
$query->select($db->quoteName('c2.' . $pk, 'item_id'))
->select($db->quoteName('c2.' . $titleField, 'item_title'))
->from($db->quoteName($tablename, 'c'))
- ->join('INNER', $db->quoteName('#__associations', 'a') . ' ON a.id = c.' . $db->quoteName($pk)
- . ' AND a.context=' . $db->quote($context)
+ ->join('INNER', $db->quoteName('#__associations', 'a') . ' ON (a.id = c.' . $db->quoteName($pk)
+ . ' AND a.context =' . $db->quote($context) . ' AND c.' . $db->quoteName($pk) . ' = ' . (int) $referenceId . ')'
)
->join('INNER', $db->quoteName('#__associations', 'a2') . ' ON a.key = a2.key')
- ->join('INNER', $db->quoteName($tablename, 'c2') . ' ON a2.id = c2.' . $db->quoteName($pk) . $categoriesExtraSql);
+ ->join('INNER', $db->quoteName($tablename, 'c2') . ' ON (a2.id = c2.' . $db->quoteName($pk) . ' AND c2.' . $db->quoteName($pk)
+ . ' != ' . $db->quote($referenceId) . $categoriesExtraSql . ')'
+ );
$query->select($db->quoteName('l.lang_id', 'lang_id'))
->select($db->quoteName('l.lang_code', 'language'))
@@ -399,9 +409,10 @@ protected function getListQuery()
->select($db->quoteName('l.title', 'language_title'))
->select($db->quoteName('l.image', 'language_image'))
->join(
- 'RIGHT', $db->quoteName('#__languages', 'l') . ' ON ' . $db->quoteName('c2.' . $langField)
- . ' = ' . $db->quoteName('l.lang_code')
- );
+ 'RIGHT', $db->quoteName('#__languages', 'l') . ' ON (' . $db->quoteName('c2.' . $langField)
+ . ' = ' . $db->quoteName('l.lang_code') . ' AND c.' . $db->quoteName($langField) . ' != l.lang_code)'
+ )
+ ->where('l.lang_code != ' . $db->quote($ignored));
// Use alias field ?
if (!empty($fields['alias']))
@@ -434,10 +445,6 @@ protected function getListQuery()
);
}
- $query->where('(c.' . $pk . ' = ' . (int) $referenceId . ' OR c.' . $pk . ' IS NULL) AND (c.'
- . $langField . ' != l.lang_code OR c.' . $langField . ' IS NULL)'
- );
-
if ($tablename === '#__categories')
{
$query->where($db->quoteName('c.extension') . ' = ' . $db->quote($extensionName));
@@ -445,15 +452,6 @@ protected function getListQuery()
}
else
{
- $tmpQuery = $db->getQuery(true);
-
- $tmpQuery->select($db->quoteName('c.' . $langField))
- ->from($db->quoteName($tablename, 'c'))
- ->where($db->quoteName('c.' . $pk) . ' = ' . (int) $referenceId);
-
- $db->setQuery($tmpQuery);
- $ignored = $db->loadResult();
-
$query->select($db->quoteName('l.lang_id', 'lang_id'))
->select($db->quoteName('l.lang_code', 'language'))
->select($db->quoteName('l.published', 'published'))
From f98a560a206c24e902427e35be7fa7bbf937ce74 Mon Sep 17 00:00:00 2001
From: GraySmog <18949832421@163.com>
Date: Tue, 12 Jun 2018 20:15:14 +0800
Subject: [PATCH 10/15] Pop up modal when clicking save buttons in com_article.
---
.../com_content/tmpl/article/edit.php | 3 ++
.../com_content/js/admin-article-edit.es6.js | 29 +++++++++++++++++++
media/com_content/js/admin-article-edit.js | 23 +++++++++++++++
3 files changed, 55 insertions(+)
create mode 100644 media/com_content/js/admin-article-edit.es6.js
create mode 100644 media/com_content/js/admin-article-edit.js
diff --git a/administrator/components/com_content/tmpl/article/edit.php b/administrator/components/com_content/tmpl/article/edit.php
index 2911b65954..fcde465183 100644
--- a/administrator/components/com_content/tmpl/article/edit.php
+++ b/administrator/components/com_content/tmpl/article/edit.php
@@ -10,12 +10,15 @@
defined('_JEXEC') or die;
use Joomla\Registry\Registry;
+use Joomla\CMS\HTML\HTMLHelper;
JHtml::_('behavior.formvalidator');
JHtml::_('behavior.keepalive');
JHtml::_('formbehavior.chosen', '#jform_catid', null, array('disable_search_threshold' => 0 ));
JHtml::_('behavior.tabstate');
+HTMLHelper::_('script', 'com_content/admin-article-edit.js', ['relative' => true, 'version' => 'auto']);
+
$this->configFieldsets = array('editorConfig');
$this->hiddenFieldsets = array('basic-limited');
$this->ignore_fieldsets = array('jmetadata', 'item_associations');
diff --git a/media/com_content/js/admin-article-edit.es6.js b/media/com_content/js/admin-article-edit.es6.js
new file mode 100644
index 0000000000..4eed0c2d98
--- /dev/null
+++ b/media/com_content/js/admin-article-edit.es6.js
@@ -0,0 +1,29 @@
+/**
+ * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+import jQuery from 'jquery';
+
+(() => {
+ 'use strict';
+
+ // Get save buttons
+ const saveButtons = ['save-group-children-apply', 'save-group-children-save', 'save-group-children-save-new', 'save-group-children-save-copy'];
+
+ document.addEventListener('DOMContentLoaded', () => {
+ saveButtons.forEach((buttonId) => {
+ const button = document.getElementById(buttonId);
+ const task = button.onclick;
+ button.removeAttribute('onclick');
+ button.addEventListener('click', (e) => {
+ e.preventDefault();
+ const assocModal = jQuery('#associationAddAssociations');
+ assocModal.modal('show');
+ assocModal.on('hidden.bs.modal', () => {
+ task();
+ });
+ });
+ });
+ });
+})();
diff --git a/media/com_content/js/admin-article-edit.js b/media/com_content/js/admin-article-edit.js
new file mode 100644
index 0000000000..1fb257c9a8
--- /dev/null
+++ b/media/com_content/js/admin-article-edit.js
@@ -0,0 +1,23 @@
+(function() {
+ 'use strict';
+
+ // Get save buttons
+ var saveButtons = ['save-group-children-apply', 'save-group-children-save', 'save-group-children-save-new', 'save-group-children-save-copy'];
+
+ document.addEventListener('DOMContentLoaded', function () {
+ saveButtons.forEach(function(buttonId) {
+ var button = document.getElementById(buttonId);
+ var task = button.onclick;
+ button.removeAttribute('onclick');
+ button.addEventListener('click', function(e) {
+ // e.preventDefault();
+ var assocModal = document.getElementById('associationAddAssociations');
+ $('#associationAddAssociations').modal('show');
+
+ $('#associationAddAssociations').on('hidden.bs.modal', function(e) {
+ task();
+ });
+ });
+ });
+ });
+})();
\ No newline at end of file
From 815e62827b9e3dec215bbbac9d0f1fc0a27dda35 Mon Sep 17 00:00:00 2001
From: GraySmog <18949832421@163.com>
Date: Sun, 17 Jun 2018 01:45:36 +0800
Subject: [PATCH 11/15] Popup modal when clicking save. Add new field for
remembering.
---
.../Controller/AutoController.php | 53 -----
.../com_associations/Model/AutoModel.php | 192 -----------------
.../com_associations/tmpl/auto/modal.php | 16 +-
.../Controller/ArticleController.php | 35 +++
.../com_content/Model/ArticleModel.php | 203 ++++++++++++++++++
.../components/com_content/config.xml | 18 ++
.../components/com_content/forms/article.xml | 12 ++
.../com_content/tmpl/article/edit.php | 6 +-
.../language/en-GB/en-GB.com_content.ini | 5 +
layouts/joomla/edit/auto.php | 21 +-
.../src/MVC/Controller/FormController.php | 38 ----
media/com_associations/js/admin-auto-modal.js | 30 +++
media/com_content/js/admin-article-edit.js | 38 +++-
13 files changed, 358 insertions(+), 309 deletions(-)
delete mode 100644 administrator/components/com_associations/Controller/AutoController.php
create mode 100644 media/com_associations/js/admin-auto-modal.js
diff --git a/administrator/components/com_associations/Controller/AutoController.php b/administrator/components/com_associations/Controller/AutoController.php
deleted file mode 100644
index ee84b81f1e..0000000000
--- a/administrator/components/com_associations/Controller/AutoController.php
+++ /dev/null
@@ -1,53 +0,0 @@
-setMessage(Text::_(''));
-
- return false;
- }
-
- // Set the model
- $model = $this->getModel('Auto', 'Administrator', array());
-
- // Preset the redirect
- $this->setRedirect(\JRoute::_('index.php?option=com_content&view=articles' . $this->getRedirectToListAppend(), false));
-
- return parent::autocreate($model);
- }
-}
\ No newline at end of file
diff --git a/administrator/components/com_associations/Model/AutoModel.php b/administrator/components/com_associations/Model/AutoModel.php
index f1629cf618..270b381455 100644
--- a/administrator/components/com_associations/Model/AutoModel.php
+++ b/administrator/components/com_associations/Model/AutoModel.php
@@ -14,8 +14,6 @@
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\DatabaseQuery;
use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper;
-use Joomla\Utilities\ArrayHelper;
-use Joomla\CMS\Table\Table;
/**
* Methods supporting a list of article records.
@@ -57,196 +55,6 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu
parent::__construct($config, $factory);
}
- /**
- * Method to automatically create associations of an item in chosen languages.
- *
- * @param int $itemId Id of current item.
- * @param array $cid An array of language ids.
- *
- * @return boolean Return true on success, false on failure.
- *
- * @since __DEPLOY_VERSION__
- */
- public function autocreate($itemId, $cid)
- {
- // Sanitize ids.
- $cid = array_unique($cid);
- $cid = ArrayHelper::toInteger($cid);
-
- // Remove any values of zero.
- if (array_search(0, $cid, true))
- {
- unset($cid[array_search(0, $cid, true)]);
- }
-
- if (empty($cid))
- {
- $this->setError(\JText::_('JGLOBAL_NO_ITEM_SELECTED'));
-
- return false;
- }
-
- // Get associations
- $associations = AssociationsHelper::getAssociationList('com_content', 'article', $itemId);
-
- // Get current user
- if (empty($this->user))
- {
- $this->user = \JFactory::getUser();
- }
-
- // Get content table
- $contentTable = Table::getInstance('Content', 'Joomla\\CMS\\Table\\');
-
- // Get language table
- $languageTable = Table::getInstance('Language', 'Joomla\\CMS\\Table\\');
-
- while (!empty($cid))
- {
- // Pop the first ID off the stack
- $pk = array_shift($cid);
-
- $contentTable->reset();
- $languageTable->reset();
-
- if (!$languageTable->load($pk) || !$contentTable->load($itemId))
- {
- if ($error = $languageTable->getError())
- {
- // Fatal error
- $this->setError($error);
-
- return false;
- }
- elseif ($error = $contentTable->getError())
- {
- // Fatal error
- $this->setError($error);
-
- return false;
- }
- else
- {
- // @TODO Add 'JLIB_APPLICATION_ERROR_AUTO_ASSOCIATIONS_ROW_NOT_FOUND'
- // Not fatal error
- $this->setError(\JText::sprintf('', $pk));
- continue;
- }
- }
-
- // Get current language
- $langCode = $languageTable->lang_code;
-
- if (!isset($itemLang))
- {
- $itemLang = $contentTable->language;
- }
-
- // If the article doesn't have associations in current language
- if (!isset($associations[$langCode]))
- {
- // Alter the title & alias
- $contentTable->title .= ' [' . $langCode . ']';
- $contentTable->alias .= ' [' . $langCode . ']';
-
- // Alter the language
- $contentTable->language = $langCode;
-
- // Reset the ID, hits, state.
- $contentTable->id = $contentTable->hits = $contentTable->state = 0;
-
- // @TODO Change category?
-
- // Get the featured state
- $featured = $contentTable->featured;
-
- // Check the row.
- if (!$contentTable->check())
- {
- $this->setError($contentTable->getError());
-
- return false;
- }
-
- // Store the row.
- if (!$contentTable->store())
- {
- $this->setError($contentTable->getError());
-
- return false;
- }
-
- // Get the new item ID
- $newId = $contentTable->getId();
-
- // Check if the article was featured and update the #__content_frontpage table
- if ($featured == 1)
- {
- $db = $this->getDbo();
- $query = $db->getQuery(true)
- ->insert($db->quoteName('#__content_frontpage'))
- ->values($newId . ', 0');
- $db->setQuery($query);
- $db->execute();
- }
-
- // Add new item to associations
- $associations[$langCode] = (int) $contentTable->getId();
- }
- else
- {
- $associations[$langCode] = (int) $associations[$langCode]['id'];
- }
- }
-
- // Get associations key for edited item
- $db = $this->getDbo();
- $query = $db->getQuery(true)
- ->select($db->quoteName('key'))
- ->from($db->quoteName('#__associations'))
- ->where($db->quoteName('context') . ' = ' . $db->quote('com_content.item'))
- ->where($db->quoteName('id') . ' = ' . (int) $itemId);
- $db->setQuery($query);
- $oldKey = $db->loadResult();
-
- // Deleting old associations for the associated items
- $query = $db->getQuery(true)
- ->delete($db->quoteName('#__associations'))
- ->where('(' . $db->quoteName('context') . ' = ' . $db->quote('.item') . ') AND ('
- . $db->quoteName('key') . ' = ' . $db->quote($oldKey) . ')'
- );
-
- $db->setQuery($query);
- $db->execute();
-
- if ($itemLang !== '*')
- {
- $associations[$itemLang] = (int) $itemId;
- }
-
- // Add new associations
- if (count($associations) > 1)
- {
- // Adding new association for these items
- $key = md5(json_encode($associations));
- $query = $db->getQuery(true)
- ->insert('#__associations');
-
- foreach ($associations as $id)
- {
- $query->values(((int) $id) . ',' . $db->quote('com_content.item') . ',' . $db->quote($key));
- }
-
- $db->setQuery($query);
- $db->execute();
- }
-
- // Clean the cache
- $this->cleanCache();
-
- return true;
- }
-
/**
* Method to auto-populate the model state.
*
diff --git a/administrator/components/com_associations/tmpl/auto/modal.php b/administrator/components/com_associations/tmpl/auto/modal.php
index e48b57c909..f8824ead32 100644
--- a/administrator/components/com_associations/tmpl/auto/modal.php
+++ b/administrator/components/com_associations/tmpl/auto/modal.php
@@ -6,24 +6,22 @@
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
+use Joomla\CMS\HTML\HTMLHelper;
defined('_JEXEC') or die;
-JHtml::_('jquery.framework');
-JHtml::_('behavior.multiselect');
+HTMLHelper::_('jquery.framework');
+HTMLHelper::_('behavior.multiselect');
+HTMLHelper::_('script', 'com_associations/admin-auto-modal.js', array('version' => 'auto', 'relative' => true));
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$canManageCheckin = JFactory::getUser()->authorise('core.manage', 'com_checkin');
$colSpan = 4;
-// @TODO add scripts
?>
-
-
-
+
+
|