diff --git a/administrator/components/com_categories/models/category.php b/administrator/components/com_categories/models/category.php index 13b223191dbae..46fcb4ca7ebee 100644 --- a/administrator/components/com_categories/models/category.php +++ b/administrator/components/com_categories/models/category.php @@ -57,6 +57,9 @@ public function __construct($config = array()) parent::__construct($config); $extension = JFactory::getApplication()->input->get('extension', 'com_content'); $this->typeAlias = $extension . '.category'; + + // Add a new batch command + $this->batch_commands['flip_ordering'] = 'batchFlipordering'; } /** @@ -819,6 +822,56 @@ protected function batchTag($value, $pks, $contexts) return true; } + /** + * Batch flip category ordering. + * + * @param integer $value The new category. + * @param array $pks An array of row IDs. + * @param array $contexts An array of item contexts. + * + * @return mixed An array of new IDs on success, boolean false on failure. + * + * @since 3.6.3 + */ + protected function batchFlipordering($value, $pks, $contexts) + { + $successful = array(); + + $db = $this->getDbo(); + $query = $db->getQuery(true); + + /** + * For each category get the max ordering value + * Re-order with max - ordering + */ + foreach ($pks as $id) + { + $query->select('MAX(ordering)') + ->from('#__content') + ->where($db->qn('catid') . ' = ' . $db->q($id)); + + $db->setQuery($query); + + $max = (int) $db->loadresult(); + $max++; + + $query->clear(); + + $query->update('#__content') + ->set($db->qn('ordering') . ' = ' . $max . ' - ' . $db->qn('ordering')) + ->where($db->qn('catid') . ' = ' . $db->q($id)); + + $db->setQuery($query); + + if ($db->execute()) + { + $successful[] = $id; + } + } + + return empty($successful) ? false : $successful; + } + /** * Batch copy categories to a new category. * diff --git a/administrator/components/com_categories/views/categories/tmpl/default_batch_body.php b/administrator/components/com_categories/views/categories/tmpl/default_batch_body.php index 4110990f81b7b..45daf66e3cb33 100644 --- a/administrator/components/com_categories/views/categories/tmpl/default_batch_body.php +++ b/administrator/components/com_categories/views/categories/tmpl/default_batch_body.php @@ -38,7 +38,7 @@
@@ -55,4 +55,15 @@ +
+
+
+ + +
+
+
+ diff --git a/administrator/language/en-GB/en-GB.lib_joomla.ini b/administrator/language/en-GB/en-GB.lib_joomla.ini index 5aa2d69e3ff5c..48cf93937c6fc 100644 --- a/administrator/language/en-GB/en-GB.lib_joomla.ini +++ b/administrator/language/en-GB/en-GB.lib_joomla.ini @@ -358,6 +358,7 @@ JLIB_HTML_ADD_TO_THIS_MENU="Add to this menu." JLIB_HTML_BATCH_ACCESS_LABEL="Set Access Level" JLIB_HTML_BATCH_ACCESS_LABEL_DESC="Not making a selection will keep the original access levels when processing." JLIB_HTML_BATCH_COPY="Copy" +JLIB_HTML_BATCH_FLIPORDERING_LABEL="Reverse the ordering of all articles in the selected categories" JLIB_HTML_BATCH_LANGUAGE_LABEL="Set Language" JLIB_HTML_BATCH_LANGUAGE_LABEL_DESC="Not making a selection will keep the original language when processing." JLIB_HTML_BATCH_LANGUAGE_NOCHANGE="- Keep original Language -"