diff --git a/libraries/joomla/table/nested.php b/libraries/joomla/table/nested.php index 4caa4b65ce7fd..59c60d61b988a 100644 --- a/libraries/joomla/table/nested.php +++ b/libraries/joomla/table/nested.php @@ -1296,9 +1296,11 @@ public function rebuild($parentId = null, $leftId = 0, $level = 0, $path = '') ->where('parent_id = %d'); // If the table has an ordering field, use that for ordering. - if (property_exists($this, 'ordering')) + $orderingField = $this->getColumnAlias('ordering'); + + if (property_exists($this, $orderingField)) { - $query->order('parent_id, ordering, lft'); + $query->order('parent_id, ' . $this->_db->quoteName($orderingField) . ', lft'); } else { diff --git a/libraries/joomla/table/table.php b/libraries/joomla/table/table.php index 552050cafb1a3..030f9dccceb7e 100644 --- a/libraries/joomla/table/table.php +++ b/libraries/joomla/table/table.php @@ -603,7 +603,7 @@ public function bind($src, $ignore = array()) } } - // If the source value is not an array or object return false. + // Check if the source value is an array or object if (!is_object($src) && !is_array($src)) { throw new InvalidArgumentException(sprintf('%s::bind(*%s*)', get_class($this), gettype($src))); @@ -1288,15 +1288,17 @@ public function isCheckedOut($with = 0, $against = null) */ public function getNextOrder($where = '') { - // If there is no ordering field set an error and return false. - if (!property_exists($this, 'ordering')) + // Check if there is an ordering field set + $orderingField = $this->getColumnAlias('ordering'); + + if (!property_exists($this, $orderingField)) { throw new UnexpectedValueException(sprintf('%s does not support ordering.', get_class($this))); } // Get the largest ordering value for a given where clause. $query = $this->_db->getQuery(true) - ->select('MAX(ordering)') + ->select('MAX(' . $this->_db->quoteName($orderingField) . ')') ->from($this->_tbl); if ($where) @@ -1348,18 +1350,22 @@ public function getPrimaryKey(array $keys = array()) */ public function reorder($where = '') { - // If there is no ordering field set an error and return false. - if (!property_exists($this, 'ordering')) + // Check if there is an ordering field set + $orderingField = $this->getColumnAlias('ordering'); + + if (!property_exists($this, $orderingField)) { throw new UnexpectedValueException(sprintf('%s does not support ordering.', get_class($this))); } + $quotedOrderingField = $this->_db->quoteName($orderingField); + // Get the primary keys and ordering values for the selection. $query = $this->_db->getQuery(true) - ->select(implode(',', $this->_tbl_keys) . ', ordering') + ->select(implode(',', $this->_tbl_keys) . ', ' . $quotedOrderingField) ->from($this->_tbl) - ->where('ordering >= 0') - ->order('ordering'); + ->where($quotedOrderingField . ' >= 0') + ->order($quotedOrderingField); // Setup the extra where and ordering clause data. if ($where) @@ -1374,15 +1380,15 @@ public function reorder($where = '') foreach ($rows as $i => $row) { // Make sure the ordering is a positive integer. - if ($row->ordering >= 0) + if ($row->$orderingField >= 0) { // Only update rows that are necessary. - if ($row->ordering != $i + 1) + if ($row->$orderingField != $i + 1) { // Update the row ordering field. $query->clear() ->update($this->_tbl) - ->set('ordering = ' . ($i + 1)); + ->set($quotedOrderingField . ' = ' . ($i + 1)); $this->appendPrimaryKeys($query, $row); $this->_db->setQuery($query); $this->_db->execute(); @@ -1408,12 +1414,16 @@ public function reorder($where = '') */ public function move($delta, $where = '') { - // If there is no ordering field set an error and return false. - if (!property_exists($this, 'ordering')) + // Check if there is an ordering field set + $orderingField = $this->getColumnAlias('ordering'); + + if (!property_exists($this, $orderingField)) { throw new UnexpectedValueException(sprintf('%s does not support ordering.', get_class($this))); } + $quotedOrderingField = $this->_db->quoteName($orderingField); + // If the change is none, do nothing. if (empty($delta)) { @@ -1424,20 +1434,20 @@ public function move($delta, $where = '') $query = $this->_db->getQuery(true); // Select the primary key and ordering values from the table. - $query->select(implode(',', $this->_tbl_keys) . ', ordering') + $query->select(implode(',', $this->_tbl_keys) . ', ' . $quotedOrderingField) ->from($this->_tbl); // If the movement delta is negative move the row up. if ($delta < 0) { - $query->where('ordering < ' . (int) $this->ordering) - ->order('ordering DESC'); + $query->where($quotedOrderingField . ' < ' . (int) $this->$orderingField) + ->order($quotedOrderingField . ' DESC'); } // If the movement delta is positive move the row down. elseif ($delta > 0) { - $query->where('ordering > ' . (int) $this->ordering) - ->order('ordering ASC'); + $query->where($quotedOrderingField . ' > ' . (int) $this->$orderingField) + ->order($quotedOrderingField . ' ASC'); } // Add the custom WHERE clause if set. @@ -1456,7 +1466,7 @@ public function move($delta, $where = '') // Update the ordering field for this instance to the row's ordering value. $query->clear() ->update($this->_tbl) - ->set('ordering = ' . (int) $row->ordering); + ->set($quotedOrderingField . ' = ' . (int) $row->$orderingField); $this->appendPrimaryKeys($query); $this->_db->setQuery($query); $this->_db->execute(); @@ -1464,20 +1474,20 @@ public function move($delta, $where = '') // Update the ordering field for the row to this instance's ordering value. $query->clear() ->update($this->_tbl) - ->set('ordering = ' . (int) $this->ordering); + ->set($quotedOrderingField . ' = ' . (int) $this->$orderingField); $this->appendPrimaryKeys($query, $row); $this->_db->setQuery($query); $this->_db->execute(); // Update the instance value. - $this->ordering = $row->ordering; + $this->$orderingField = $row->$orderingField; } else { // Update the ordering field for this instance. $query->clear() ->update($this->_tbl) - ->set('ordering = ' . (int) $this->ordering); + ->set($quotedOrderingField . ' = ' . (int) $this->$orderingField); $this->appendPrimaryKeys($query); $this->_db->setQuery($query); $this->_db->execute(); diff --git a/libraries/legacy/model/admin.php b/libraries/legacy/model/admin.php index 3aaefa6ed8c30..dcfff892906d1 100644 --- a/libraries/legacy/model/admin.php +++ b/libraries/legacy/model/admin.php @@ -1308,6 +1308,8 @@ public function saveorder($pks = array(), $order = null) return JError::raiseWarning(500, JText::_($this->text_prefix . '_ERROR_NO_ITEMS_SELECTED')); } + $orderingField = $table->getColumnAlias('ordering'); + // Update ordering values foreach ($pks as $i => $pk) { @@ -1320,9 +1322,9 @@ public function saveorder($pks = array(), $order = null) unset($pks[$i]); JLog::add(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), JLog::WARNING, 'jerror'); } - elseif ($table->ordering != $order[$i]) + elseif ($table->$orderingField != $order[$i]) { - $table->ordering = $order[$i]; + $table->$orderingField = $order[$i]; if ($type) {